mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
refactor(cloudcmd) route add to express middleware
This commit is contained in:
parent
168e29418a
commit
3b86ca97d3
2 changed files with 25 additions and 17 deletions
37
cloudcmd.js
37
cloudcmd.js
|
|
@ -197,27 +197,34 @@
|
|||
/**
|
||||
* routing of server queries
|
||||
*/
|
||||
function route(pParams) {
|
||||
var lRet = main.checkParams(pParams);
|
||||
function route(request, response, callback) {
|
||||
var ret, name, params, isAuth, isFS;
|
||||
|
||||
if (lRet) {
|
||||
var p = pParams;
|
||||
if (request && response) {
|
||||
name = main.getPathName(request);
|
||||
isAuth = Util.strCmp(name, ['/auth', '/auth/github']);
|
||||
isFS = Util.strCmp(name, '/') || Util.isContainStrAtBegin(name, FS);
|
||||
|
||||
if ( Util.strCmp(p.name, ['/auth', '/auth/github']) ) {
|
||||
Util.log('* Routing' +
|
||||
'-> ' + p.name);
|
||||
params = {
|
||||
request : request,
|
||||
response : response,
|
||||
name : name
|
||||
};
|
||||
|
||||
if (isAuth) {
|
||||
Util.log('* Routing' + '-> ' + name);
|
||||
|
||||
pParams.name = main.HTMLDIR + p.name + '.html';
|
||||
lRet = main.sendFile( pParams );
|
||||
params.name = main.HTMLDIR + name + '.html';
|
||||
main.sendFile(params);
|
||||
} else if (isFS)
|
||||
sendContent(params);
|
||||
else {
|
||||
ret = false;
|
||||
Util.exec(callback);
|
||||
}
|
||||
else if ( Util.isContainStrAtBegin(p.name, FS) || Util.strCmp( p.name, '/') )
|
||||
lRet = sendContent( pParams );
|
||||
|
||||
else
|
||||
lRet = false;
|
||||
}
|
||||
|
||||
return lRet;
|
||||
return ret;
|
||||
}
|
||||
|
||||
function sendContent(pParams) {
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@
|
|||
lHTTPServer = function() {
|
||||
expressApp = express.getApp([
|
||||
Rest,
|
||||
Route,
|
||||
join,
|
||||
controller
|
||||
]);
|
||||
|
|
@ -182,8 +183,8 @@
|
|||
if (lConfig.rest && !expressApp)
|
||||
lRet = Util.exec(Rest, pReq, pRes);
|
||||
|
||||
if (!lRet && Route)
|
||||
lRet = Util.exec(Route, data);
|
||||
if (!lRet && !expressApp)
|
||||
lRet = Util.exec(Route, pReq, pRes);
|
||||
|
||||
if (!lRet && !expressApp)
|
||||
lRet = join(pReq, pRes);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue