Browse Source

fix router

HonorLee 5 years ago
parent
commit
52d1ad257a
1 changed files with 15 additions and 12 deletions
  1. 15 12
      system/lib/core/router.js

+ 15 - 12
system/lib/core/router.js

@@ -66,19 +66,22 @@ var Router ={
         }
     },
     runHandler:function(path,handlerFile,handler,method,res){
-        if(RouterRule && RouterRule[path] && RouterRule[path]['permission'].length){
+        if(RouterRule && RouterRule[path] && (RouterRule[path]['permission']).length){
             let status = handler.session.get('status');
-            if(!new RegExp(status).exec(RouterRule[path]['permission'])){
-                let control = (RouterRule[path]['onerror']).split(':');
-                let way = control[0];
-                let output = control[1];
-                if(way=='R'){
-                    if(!output) output = '/';
-                    return handler.endRedirect(output);
-                }
-                if(way=='A'){
-                    if(!output) output = 'Unauthorized';
-                    return handler.endAPI(-1,output);
+            if((RouterRule[path]['method'] && RouterRule[path]['method'].length && new RegExp(method).exec(RouterRule[path]['method'])) || (!RouterRule[path]['method'] || RouterRule[path]['method'].length==0)){
+                if(!new RegExp(status).exec(RouterRule[path]['permission'])){
+                    let control = (RouterRule[path]['onerror']).split(':');
+                    let way = control[0];
+                    let output = control[1];
+                    if(way=='R'){
+                        if(!output) output = '/';
+                        return handler.endRedirect(output);
+                    }
+                    if(way=='A'){
+                        if(!output) output = 'Unauthorized';
+                        return handler.endAPI(-1,output);
+                    }
+                    return;
                 }
             }
         }