
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
clay-router
Advanced tools
This is a package developed to group Express routes. Clay-router can help you to order your project splitting your router logic in controllers files and middlewares files.
controler file is a javascript file which contains an object with methods to handle a particular route.
middleware file is a javascript file which contains an object with methods to handle routes before the route be handle by a controller method.
To start with clay-routes you have to install express and clay-router package.
$ npm install express
$ npm install clay-router
Create controllers and middlewares folders.
$ mkdir controllers
$ mkdir middlewares
Create controllers and middlewares with the following schema.
controllers/myIndexController.js
let myIndexController = {
myMethod1:(req,res)=>{
res.send({msg:'this is the first method'})
},
myMethod2:(req,res)=>{
//this method use a req.test value setted in the middleware file
res.send({msg:req.test})
}
}
module.exports = myIndexController
middlewares/myMiddleware.js
let myMiddleware = {
myMethod1:(req,res, next)=>{
req.test = 'abcd'
next()
}
}
module.exports = myMiddleware
You can create controllers files an middlewares files as many you want.
Create an clay-router instance.
var clay = require('clay-router')
clayRouter = new clay({
controllerPath:'controllers',
middlewarePath:'middlewares'
})
Group your routes and set the controllers and middlewares.
clayRouter.group('/test',['myMiddleware@myMethod1'],[
{method:'get', path:'/test1',handler:'myIndexController@myMethod1'},
{method:'get', path:'/test2',handler:'myIndexController@myMethod2'}
])
Group has three arguments:
The principal url ('/test')
An array of middlewares: a string with the following structure
'middlewarefilename@method'
An array of routes: routes are objects with the following structure:
{
method:'get/post',
path:'subpath',
handler:'controllerfilename@method'
}
Use the router property to register your routes in your Express app. Your app file will looks like this.
var express = require('express');
var app = express();
var clay = require('clay-router')
clayRouter = new clay({
controllerPath:'controllers',
middlewarePath:'middlewares'
})
clayRouter.group('/test',['myMiddleware@myMethod1'],[
{method:'get', path:'/test1',handler:'myIndexController@myMethod1'},
{method:'get', path:'/test2',handler:'myIndexController@myMethod2'}
])
//you can use express methods in the router property object like that
clayRouter.router.get('/index',(req,res)=>{
res.send('index')
})
clayRouter.router.get('/example',(req,res)=>{
res.send('example')
})
//register the routes
app.use('/',clayRouter.router)
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
})
FAQs
express router
We found that clay-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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.