Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
simple composable routing middleware for nodejs
CoffeeScript
Branch: master

1.5.0

latest commit 266e10d3fe
@snd authored
Failed to load latest commit information.
lib use url-pattern 0.9
src use url-pattern 0.9
test improve the way coffee is compiled to js
.gitignore ignore node_modules
.travis.yml make travis build work
LICENSE initial commit
README.md improve readme example
package.json 1.5.0

README.md

passage

NPM Package Build Status Dependencies

simple composable routing middleware for nodejs

npm install passage
var http = require('http');
var passage = require('passage');
var sequenz = require('sequenz');

var server = http.createServer(sequenz(
  passage.any('*', function(req, res, next) {
    console.log('i got called for any method and any url');
    next();
  }),
  passage.get('/', function(req, res, next) {
    res.end('i got called for GET /');
  }),
  passage.any('/users*', function(req, res, next) {
    console.log('i got called for an url that starts with /users with any method');
    next();
  passage.get('/users/:userId/posts/:postId', function(req, res, next, params) {
    res.end('i got called for GET /users/' + params.userId + '/posts/' + params.postId);
  }),
  passage.post('/users/:userId/posts', function(req, res, next, params) {
    res.end('i got called for POST /users/' + params.userId + '/posts/');
  }),
  passage.put('/users/:userId/posts/:postId', function(req, res, next, params) {
    res.end('i got called for PUT /users/' + params.userId + '/posts/' + params.postId);
  }),
  passage.patch('/users/:userId/posts/:postId', function(req, res, next, params) {
    res.end('i got called for PATCH /users/' + params.userId + '/posts/' + params.postId);
  }),
  passage.delete('/users/:id', function(req, res, next, params) {
    res.end('i got called for DELETE /users/' + params.id);
  })
));

server.listen(80);

sequenz takes an array of middlewares and returns a single middleware that runs the middlewares in order.

the first argument to the passage functions can by any url-pattern.

vhost example

var http = require('http');
var connect = require('connect');
var passage = require('passage');
var sequenz = require('sequenz');

var routes = sequenz(
  passage.vhost('alice.example.com', connect.static('public/alice')),
  passage.vhost('bob.example.com', connect.static('public/bob')),
  passage.vhost(':sub.example.com', function(req, res, next, params) {
    console.log('i got called for ' + params.sub + '.example.com');
    next();
);

server = http.createServer(routes);

server.listen(80);

license: MIT

Something went wrong with that request. Please try again.