mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-20 18:18:56 +00:00
feature(express) add join as express middleware
This commit is contained in:
parent
bbfff3c704
commit
881ce04f4b
2 changed files with 25 additions and 10 deletions
|
|
@ -97,7 +97,11 @@
|
|||
},
|
||||
|
||||
lHTTPServer = function() {
|
||||
expressApp = express.getApp(controller);
|
||||
expressApp = express.getApp([
|
||||
join,
|
||||
controller
|
||||
]);
|
||||
|
||||
Server = http.createServer(expressApp || controller);
|
||||
|
||||
Server.on('error', Util.log.bind(Util));
|
||||
|
|
@ -183,10 +187,8 @@
|
|||
if (!lRet && Route)
|
||||
lRet = Util.exec(Route, data);
|
||||
|
||||
if (!lRet)
|
||||
lRet = join(pReq, pRes, function(error) {
|
||||
main.sendError(data, error);
|
||||
});
|
||||
if (!lRet && !expressApp)
|
||||
lRet = join(pReq, pRes);
|
||||
|
||||
if (!lRet) {
|
||||
lName = data.name;
|
||||
|
|
@ -263,7 +265,11 @@
|
|||
|
||||
if (error)
|
||||
if (!response.headersSent)
|
||||
Util.exec(callback, error);
|
||||
main.sendError({
|
||||
request : request,
|
||||
response : response,
|
||||
name : path
|
||||
}, error);
|
||||
else {
|
||||
Util.log(error);
|
||||
errorStr = error.toString();
|
||||
|
|
@ -304,7 +310,8 @@
|
|||
}
|
||||
Util.asyncCall(funcs, readPipe);
|
||||
}
|
||||
}
|
||||
} else
|
||||
Util.exec(callback);
|
||||
|
||||
return isJoin;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,9 @@
|
|||
oldName,
|
||||
app = express && express();
|
||||
|
||||
exports.getApp = function(controller) {
|
||||
var config = main.config,
|
||||
exports.getApp = function(middleware) {
|
||||
var i, n, middle,
|
||||
config = main.config,
|
||||
auth = config.auth;
|
||||
|
||||
if (app) {
|
||||
|
|
@ -30,7 +31,14 @@
|
|||
app.use(httpAuth.connect(basic));
|
||||
}
|
||||
|
||||
app.all('*', controller);
|
||||
if (middleware) {
|
||||
n = middleware.length;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
middle = middleware[i];
|
||||
app.use(middle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return app;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue