Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
app-router
Advanced tools
routing for expressjs
var express= require("express");
var app = express();
var router = require("app-router");
router(app).setCWD(__dirname).route("./routes/route.json");
Set current working directory (CWD) relative to all controllers path and route.json
setCWD(__dirname)
Throwing Error on unresolved action of route (default is true)
throwErrorOnWrongActionPath(false)
console.log all routing mapped by app-router (default is false)
logRoute(true)
Attach action manually to route in application (useful for other frameworks) (optional) (not required in express)
letMeAttach(function(method, route, actions){
// method {String} = get, post, delete etc
// route {String} = given by user or created by resource eg /user
// actions {Array} = an array of actions resolved
// routing example in express
actions.unshift(route);
app[method].apply(app, actions);
})
Use .format route in resource routing , by falsing it no route for .format will attach to resource routing. (default is true)
useFormatInResource(false)
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 Action (in controller ./controllers/user_controller.js)
GET /user -> index
GET /user.:format -> index
GET /user/new -> new
GET /user/new.:format -> new
POST /user -> create
POST /user.:format -> create
GET /user/:id -> show
GET /user/:id.:format -> show
GET /user/:id/edit -> edit
GET /user/:id/edit.:format -> edit
PUT /user/:id -> update
PUT /user/:id.:format -> update
DELETE /user/:id -> destroy
DELETE /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
router(app).setCWD(__dirname).route("./routes/route.yml");
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
router(app).setCWD(__dirname).route("./routes/route.txt");
sample route.txt
VARIABLE cp ./controllers/my_controller
VARIABLE other_controller ./controllers/other_controller.js
GET /user_controller {cp}:myMiddleWareFunction {cp}:myMethod
GET /user/:id ./controllers/other_controller:myClass.myAction
POST /hello ./controllers/my_controller:createApp
PUT /hello ./controllers/my_controller:createApp
DELETE /user ./controllers/other_controller.js:destroyApp
RESOURCE /res {cp}
RESOURCE /user ./controllers/user_controller.js
FAQs
Routing for expressjs
The npm package app-router receives a total of 6 weekly downloads. As such, app-router popularity was classified as not popular.
We found that app-router demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.