Socket
Socket
Sign inDemoInstall

midd-router

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

midd-router

router middleware for midd


Version published
Weekly downloads
2
Maintainers
2
Weekly downloads
 
Created
Source

Router middleware for midd

Features

  • Support use() all() get() post() and other http verbs
  • Support url pattern like express router: use('/:name', ...)
  • Support url rewrite in route
  • Support nested routers
  • Routes are also promise-based
  • Support express middlewares by router.express.VERB()

Usage

const middRouter = require('midd-router');

const router = middRouter();
router.use('/a', async (req, resp, next)=>{
  await next();
})
router.get('/b', (req, resp, next)=>{
  return new Promise((resolve, reject)=>{
    setTimeout(resolve, 1000);
  }).then(next)
})
router.express.use(compression());
app.use(router)

API

middRouter(options)

Options have:

  • params: object. The default params for req.params.
router.use|all|get|post|...([pattern], ...middlewares)

Attach routes to the pattern. If no pattern specified, they will be attached at root path('/').

router.express.use|all|get|post|...([pattern], ...middlewares)
req.params

If the pattern used in router verbs have named part(like '/:name'), req.params will contain the named part and its value.

req.routePath

req.routePath represents current route's context(or position). See there are router A and router B, and their relations are described by routerA.use('/a', routerB). So router B's routePath = router A's routePath + /a.

License

Licensed under MIT

Copyright (c) 2017 Tian Jian

Keywords

FAQs

Package last updated on 22 Feb 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc