Authored by weiqingting

提交

... ... @@ -84,7 +84,7 @@ module.exports = {
var user = req.body.user;
var password = req.body.password;
var errcallback = function (err) {
return callback(null, result);
return callback(err, result);
}
common.Ilogin(user, password).allRight().sessionAsync(user, password).done(function (IloginRes,allRes,sesRes) {
var userData = IloginRes.data, cookie = sesRes.caseless.dict["set-cookie"];
... ...
... ... @@ -334,10 +334,14 @@ queue.prototype = {
}
function __sendRequest(options, success, fail,wlen,i,args) {
Request(options, function (error, response, body) {
if (!wlen.len) {
return;
}
var _err_ = new Error(), obj;
if (error) {
console.info("Error [request"+options.url+"]:" + options.title);
console.error(error);
wlen.len = 0;
fail && fail(error);
return;
}
... ... @@ -349,6 +353,7 @@ function __sendRequest(options, success, fail,wlen,i,args) {
_err_.message = "Error[json parse@" + options.title + "--"+options.url+"]:" + body;
console.info(_err_.message);
console.error(_err_);
wlen.len = 0;
fail && fail(_err_);
return;
}
... ... @@ -359,14 +364,16 @@ function __sendRequest(options, success, fail,wlen,i,args) {
_err_.message = "Error[response state @" + options.title + "--"+options.url+"]:" + response.statusCode;
console.info(_err_.message);
console.error(_err_);
wlen.len = 0;
fail && fail(_err_);
return;
}
} catch (err) {
console.info("Error[response to json @" + options.title + "--"+options.url+"]");
console.info(response);
console.error(err);
wlen.len = 0;
fail && fail(err);
return;
}
... ... @@ -379,5 +386,4 @@ function __sendRequest(options, success, fail,wlen,i,args) {
});
}
module.exports = Interfacer;
\ No newline at end of file
... ...
... ... @@ -4,7 +4,6 @@ module.exports=function(app) {
app.get("/login","common.Login");
app.get("/logout","common.Login",function (req) {
console.log("delete session");
delete req.session.user;
});
... ...
... ... @@ -73,8 +73,8 @@ var apiCofig = {
}
app.use(session(options));
},
useToOuter:function(app){
app.use(grayroute());
useToOuter:function(app,controllers){
app.use(grayroute(controllers));
}
};
... ...
... ... @@ -84,7 +84,7 @@ module.exports = {
var user = req.body.user;
var password = req.body.password;
var errcallback = function (err) {
return callback(null, result);
return callback(err, result);
}
common.Ilogin(user, password).allRight().sessionAsync(user, password).done(function (IloginRes,allRes,sesRes) {
var userData = IloginRes.data, cookie = sesRes.caseless.dict["set-cookie"];
... ... @@ -109,12 +109,8 @@ module.exports = {
id: data.shopsId
});
});
console.log("userInfo",userInfo);
req.session.user = userInfo;
if (cookie && cookie.length > 0) {
console.log("cookie",cookie[0]);
req.session.gray = cookie[0];
result = { code: 200, message: "登录成功" };
}
... ... @@ -139,7 +135,6 @@ module.exports = {
},
gray: function (req, callback,common) {
var result = { code: 201, message: "没有权限" };
console.log("session gray");
if (req.session && req.session.user) {
var user = req.session.user;
var path = req.route?req.route.path[0]:req.originalUrl.replace(/\?.+/, '');
... ...
... ... @@ -99,7 +99,6 @@ module.exports = function (apiCofig) {
/*路由控制*/
var KLH = function (obj, method, guid) {
return function (req, res) {
console.log("我找到控制器了");
obj[method].call(obj, guid, req, res);
}
};
... ... @@ -115,12 +114,11 @@ module.exports = function (apiCofig) {
App.use(function (req, res, next) {
var err = new Error('Not Found');
err.status = 404;
console.error(err.message);
console.log("wo caocao");
// console.error(err.message);
next(err);
});
/*後置中间间*/
apiCofig.useToOuter && apiCofig.useToOuter(App);
apiCofig.useToOuter && apiCofig.useToOuter(App, ContRegisters);
App.use(function (req, res, next) {
res.end();
... ...
... ... @@ -40,7 +40,7 @@ Controller.prototype.__define=function(method,router,view,apis,callback,clientmo
var req = args[0], res = args[1];
console.log("session Controller");
var local = { __session__: req.session, $extend: {} };
/*如果接口不存在 就实现express 原来的方法*/
if(!apis.length){
... ... @@ -49,7 +49,6 @@ Controller.prototype.__define=function(method,router,view,apis,callback,clientmo
model=callback.apply(local, args);
}
if(view){
console.log("view1");
res.render(view,local,me.client(res,view,model,clientmodel));
}
... ... @@ -79,7 +78,6 @@ Controller.prototype.__define=function(method,router,view,apis,callback,clientmo
if (model&&model.readable) {
model.pipe(res);
}else if (view && method == "get" && !req.xhr) {
console.log("view2");
res.render(view, local, me.client(res, view, model,clientmodel));
} else {
res.json(model);
... ...
... ... @@ -334,10 +334,14 @@ queue.prototype = {
}
function __sendRequest(options, success, fail,wlen,i,args) {
Request(options, function (error, response, body) {
if (!wlen.len) {
return;
}
var _err_ = new Error(), obj;
if (error) {
console.info("Error [request"+options.url+"]:" + options.title);
console.error(error);
wlen.len = 0;
fail && fail(error);
return;
}
... ... @@ -349,6 +353,7 @@ function __sendRequest(options, success, fail,wlen,i,args) {
_err_.message = "Error[json parse@" + options.title + "--"+options.url+"]:" + body;
console.info(_err_.message);
console.error(_err_);
wlen.len = 0;
fail && fail(_err_);
return;
}
... ... @@ -359,6 +364,7 @@ function __sendRequest(options, success, fail,wlen,i,args) {
_err_.message = "Error[response state @" + options.title + "--"+options.url+"]:" + response.statusCode;
console.info(_err_.message);
console.error(_err_);
wlen.len = 0;
fail && fail(_err_);
return;
}
... ... @@ -367,6 +373,7 @@ function __sendRequest(options, success, fail,wlen,i,args) {
console.info("Error[response to json @" + options.title + "--"+options.url+"]");
console.info(response);
console.error(err);
wlen.len = 0;
fail && fail(err);
return;
}
... ...
... ... @@ -10,10 +10,10 @@ function addFiles(req) {
_.merge(body, req.body);
return body;
}
module.exports=function(){
module.exports=function(controllers){
var Iaccount=global.Register.system;
return function(err,req,res,next){
console.error(err);
console.log(err);
console.log("req.originalUrl:"+req.originalUrl)
if(err.status=="404"){
var method = req.method.toLowerCase();
... ...