1.0.6 • Published 4 years ago

connect-route-ext v1.0.6

Weekly downloads
36
License
MIT
Repository
github
Last release
4 years ago

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.

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago