connect-route-ext
v0.2.2 router connect
About
Extended, but still simple and fast router for connect or other middleware with the same interface.
Installation
You will need node version >= 6 and npm to install and use this module:
npm install connect-route-ext
Usage
var connectRoute = require('connect-route-ext')
var connect = require('connect')
var app = connect()
app.use(connectRoute(function (router) {
router.get('/', function (req, res, next) {
res.end('index')
})
.get('/home', function (req, res, next) {
res.end('home')
})
.get('/home/:id', function (req, res, next) {
res.end('home ' + req.params.id)
})
.get('/home/*path', function (req, res, next) {
res.end('home ' + req.params.path.join('/'))
})
.post('/home', function (req, res, next) {
res.end('POST to home')
})
function authenticate(req, res, next) {
if (authenticated(req)) {
next()
} else {
fail(res)
}
}
router.get('/secret', authenticate, function (req, res, next) {
res.end('secret')
})
}))
app.listen(3000)
Background
This project started as a fork of connect-route and added functionality to support usage scenarios needed by a more complex server, which supports an SPA:
- Match the rest of the path by "*path" parameter
- Pass multiple chained handlers to a single route
Contributing
In lieu of a formal style guide, take care to maintain the existing coding style.
License
Copyright (c) 2017-2020 Ferdinand Prantl Copyright (c) 2012 Vadim M. Baryshev
Licensed under the MIT license.
npm i [email protected]
Metadata
- MIT
- >= 0.10.0
- Ferdinand Prantl
- released 12/22/2017