|
@@ -19,45 +19,26 @@ var Router ={
|
|
|
});
|
|
|
},
|
|
|
goHandler:function(path,req,res){
|
|
|
- let pathArr = path.split('/');
|
|
|
let method = 'index';
|
|
|
- let match = false;
|
|
|
- if(path=='/') path = '/index';
|
|
|
- let expArr = [],methodMark = {};
|
|
|
let handlerFile;
|
|
|
- //
|
|
|
- handlerFile = path + '/index.js';
|
|
|
- expArr.push(handlerFile);
|
|
|
- methodMark[handlerFile] = 'index';
|
|
|
- //
|
|
|
- handlerFile = path + '.js';
|
|
|
- expArr.push(handlerFile);
|
|
|
- methodMark[handlerFile] = 'index';
|
|
|
- //
|
|
|
- if(path!='/index'){
|
|
|
- if(pathArr.length==2){
|
|
|
- method = pathArr[1];
|
|
|
- handlerFile = '/index.js';
|
|
|
- expArr.push(handlerFile);
|
|
|
- methodMark[handlerFile] = method;
|
|
|
+ if(path=='/'){
|
|
|
+ handlerFile = '/index.js'
|
|
|
+ }else if(path.lastIndexOf('/')==(path.length-1)){
|
|
|
+ handlerFile = `${path}index.js`;
|
|
|
+ }else{
|
|
|
+ if(FILE.existsSync(Core.Path.Handler + `${path}.js`)){
|
|
|
+ handlerFile = `${path}.js`;
|
|
|
}else{
|
|
|
+ let pathArr = path.split('/');
|
|
|
method = pathArr.pop();
|
|
|
- handlerFile = pathArr.join('/') + '/index.js';
|
|
|
- expArr.push(handlerFile);
|
|
|
- methodMark[handlerFile] = method;
|
|
|
- //
|
|
|
- handlerFile = pathArr.join('/') + '.js';
|
|
|
- expArr.push(handlerFile);
|
|
|
- methodMark[handlerFile] = method;
|
|
|
+ path = pathArr.join('/');
|
|
|
+ if(FILE.existsSync(Core.Path.Handler + `${path}.js`)){
|
|
|
+ handlerFile = `${path}.js`;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- match = new RegExp(expArr.join('|')).exec(CACHE.HandlersString);
|
|
|
- if(!match) return Router._error('No such handler ['+handlerFile+']',res);
|
|
|
-
|
|
|
- method = methodMark[match];
|
|
|
- handlerFile = Core.Path.Handler + match;
|
|
|
- if(method=='') method = 'index';
|
|
|
+ if(!handlerFile) return Router._error('No such handler ['+path+']',res);
|
|
|
+ handlerFile = Core.Path.Handler + handlerFile;
|
|
|
if(method=='__construct') return Router._error('__construct can\'t be called outside in ['+handlerFile+']',res);
|
|
|
let handler;
|
|
|
try {
|