Nostalgic Punchcard Missing

    connect-route-ext

    1.0.6 • Public • Published

    NPM version Build Status codecov dependencies Status devDependencies Status semantic-release

    NPM Downloads

    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.

    Install

    npm i connect-route-ext

    DownloadsWeekly Downloads

    77

    Version

    1.0.6

    License

    MIT

    Unpacked Size

    12.8 kB

    Total Files

    5

    Last publish

    Collaborators

    • avatar