app-router
routing for expressjs
usage
var express= ;var app = ;var router = ;;
Set current working directory (CWD) relative to all controllers path and route.json
Throwing Error on unresolved action of route (default is true)
console.log all routing mapped by app-router (default is false)
Attach action manually to route in application (useful for other frameworks) (optional) (not required in express)
Use .format route in resource routing , by falsing it no route for .format will attach to resource routing. (default is true)
sample route.json
"VARIABLE": "cp":"./controllers/my_controller" "other_controller":"./controllers/other_controller.js" "GET": "/user" : "{cp}:myMiddleWareFunction" "{cp}:myMethod" "/user/:id" : "{cp}:myClass.myMethod" "POST": "/hello" : "./controllers/my_controller:createApp" "PUT": "/hello" : "{other_controller}:helloPut" "DELETE": "/user" : "./controllers/other_controller.js:destroyApp" "RESOURCE": "/res" : "{cp}" "/user" : "./controllers/user_controller.js"
Resource action mapping
Actions are mapped accordingly:
"RESOURCE": "/user" : "./controllers/user_controller" Method Route GET /user -> indexGET /user:format -> indexGET /user/new -> newGET /user/new:format -> newPOST /user -> createPOST /user:format -> createGET /user/:id -> showGET /user/:id:format -> showGET /user/:id/edit -> editGET /user/:id/edit:format -> editPUT /user/:id -> updatePUT /user/:id:format -> updateDELETE /user/:id -> destroyDELETE /user/:id:format -> destroy
Basic syntax for route.json
"/app_route" : "path_to_controller:method_name"
OR
"/app_route" : "path_to_controller:class_name.method_name"
OR
"/app_route" : "path_to_controller:middleware_one" "path_to_controller:middleware_two" "path_to_controller:method_name"
Yaml routing in app-router
;
sample route.yml
VARIABLE: cp: "./controllers/my_controller" other_controller: "./controllers/other_controller.js"GET: /user: - "{cp}:myMiddleWareFunction" - "{cp}:myMethod" /user/:id: "{cp}:myClass.myMethod"POST: /hello: "./controllers/my_controller:createApp"PUT: /hello: "{other_controller}:helloPut"DELETE: /user: "./controllers/other_controller.js:destroyApp"RESOURCE: /res: "{cp}" /user: "./controllers/user_controller.js"
Text routing in app-router
;
sample route.txt
VARIABLE cp /controllers/my_controller VARIABLE other_controller /controllers/other_controllerjs GET /user_controller cp:myMiddleWareFunction cp:myMethod GET /user/:id /controllers/other_controller:myClassmyAction POST /hello /controllers/my_controller:createApp PUT /hello /controllers/my_controller:createApp DELETE /user /controllers/other_controllerjs:destroyApp RESOURCE /res cp RESOURCE /user /controllers/user_controllerjs