Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kettek/express-mega-router
Express middleware that allows dynamic routes and middleware.
https://github.com/kettek/express-mega-router
Last synced: 19 days ago
JSON representation
Express middleware that allows dynamic routes and middleware.
- Host: GitHub
- URL: https://github.com/kettek/express-mega-router
- Owner: kettek
- License: gpl-3.0
- Created: 2017-08-03T19:51:13.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-08-10T06:57:16.000Z (over 7 years ago)
- Last Synced: 2024-08-11T09:47:51.760Z (5 months ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# express-mega-router
A simple Express middleware that allows for dynamic routing and middleware.It uses `path-to-regexp` for route parsing, thereby imposing all limitations inherent within.
Uses Babel for transpiling ES6 into ES5.
## Installation
npm install express-mega-router --save## Usage
const express = require('express');
const megaRouter = require('express-mega-router')();const app = express();
app.use(megaRouter.middleware);### Basic route
megaRouter.get('/test', function(req, res) {
res.send('Test Route');
});### Catch all methods
megaRouter.all('/*', function(req, res, next) {
console.log('catch-all engaged!');
next();
});### One-time use route
function singleUseRoute(req, res) {
res.send('Single-use route!');
megaRouter.unget('/*', singleUseRoute);
});
megaRouter.get('/*', singleUseRoute);### Clearing all routes for a path
megaRouter.unget('/*');### Mixed route arguments
megaRouter.get('/*',
function(req, res, next) {
console.log('A');
next();
},
function(req, res, next) {
console.log('B');
next();
},
[
function(req, res, next) {
console.log('C');
next();
},
function(req, res, next) {
console.log('D');
next();
}
]);## License
GPLv3