
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
restify-router-config
Advanced tools
The laziest way to route your restify app.
This is an effort to maximize laziness in routing restify app. This tool includes grouping of routes, sorting of routes, and applying multiple middleware in most convenient way, of course the structure is inspired by react-router-config.
NOTE: This module is also compatible with express but usage may vary.
npm install -S restify-router-config
import * as restify from 'restify'
import router from 'restify-router-config'
import { getUserById, getUser, login } from './controllers/users'
import { restrictedRoute } from './middlewares'
/** create restify server */
const server = restify.createServer()
/** configure your routes */
// NOTE: you may or may not use group, but for the sake of grouping up
// your endpoints it's best to use it.
router(server)([
{
group: 'users',
routes: [
{
match: '/:id', // would generate /users/:id route
middleware: restrictedRoute,
method: 'get',
action: getUserById
},
{
match: '/', // would generate /users
method: 'get',
action: getUser
}
]
},
{
match: '/login', // would generate login
method: 'post',
action: login
}
])
server.listen(8080)
const router = require('restify-router-config')
const restify = require('restify')
const apiAuth = (req, res, next) => {
console.log('authed!');
next()
}
const loggingMW = (req, res, next) => {
console.log(req._timeStart)
next()
}
const logDone = (req, res, next) => {
console.log('done!')
next()
}
router(server) ([
{
group: 'api/v1',
middleware: apiAuth,
routes: [
{
match: '/hello',
method: 'get',
action: (req, res, next) => res.send('hello')
},
{
group: 'users',
middleware: [
['before', loggingMW],
['after', logDone]
],
routes: [
{
match: '/:id',
method: 'get',
action: (req, res, next) => {
res.send('hello')
next()
}
},
{
match: '/:id/friends',
method: 'get',
action: (req, res, next) => {
res.send('hello')
next()
}
},
{
match: '/',
method: 'get',
action: (req, res, next) => {
res.send('hello')
next()
}
}
]
}
]
}
])
server.listen(4000)
The example above would generate the following routes:
[get] - /api/v1/users/:id/friends
[get] - /api/v1/users/:id
[get] - /api/v1/hello
[get] - /api/v1/users
You may choose to add middleware after the function's execution, in order to do that you must use the following syntax:
import * as restify from 'restify'
import router from 'restify-router-config'
import { getUserById } from './controllers/users'
import { authenticate, logger } from './middlewares'
/** create restify server */
const server = restify.createServer()
/** configure your routes */
// NOTE: you may or may not use group, but for the sake of grouping up
// your endpoints it's best to use it.
router(server)([
{
match: '/users/:id',
method: 'get',
middleware: [
['before', authenticate],
['after', logger]
]
action: getUserById
}
])
server.listen(8080)
in the example above, the /users/:id
route is authenticated first, then executes getUserById
, after the execution of the getUserById
the logger
is executed right away.
You don't have to, but if you're used to react-router-config
, then this would make it easier for you to configure your routes as
it is almost similar structure to react-router-config
, another advantage of using this route tool is you can easily chain your middleware. For instance if you want to protect all of your routes, and at same time a single route would require additional middleware, you'd do it like this:
import { anotherMiddleware } from './middlewares'
router(server)([
{
// assuming that you want to protect all routes under /users
group: 'users',
middleware: restrictedRoute,
routes: [
{
match: '/:id',
middleware: anotherMiddleware,
method: 'get',
action: getUserById
},
{
match: '/',
method: 'get',
action: getUser
}
]
}
])
the code from above would use restrictedRoute
middleware first, and if you're going to access /users/:id,
it would also use anotherMiddleware
middleware.
FAQs
The laziest way to route your restify app.
The npm package restify-router-config receives a total of 21 weekly downloads. As such, restify-router-config popularity was classified as not popular.
We found that restify-router-config 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
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.