pfadfinder
v1.0.2
Published
pfadfinder ==========
Downloads
4
Readme
pfadfinder
Simple framework independent routing middleware for node.js.
Motivation
This was build as a dropin replacement for the routing middleware in express.js.
pfadfinder
should do the same, but in a decoupled way so it can be used
with other middleware frameworks, too.
Usage
http = require 'http'
pfadfinder = require 'pfadfinder'
router = pfadfinder()
router.get '/hello', (req, res) -> res.end 'hello world'
router.get '/hello/:name', (req, res) -> res.end "hello #{req.params.name}"
router.post '/hello/:name', (req, res) -> res.end "post to #{req.params.name}"
server = http.createServer router.middleware
server.listen 8888
You can find this example and another in the example
folder.
Composition
pfadfinder can be composed with other middlewares.
For example if no route is matched, pfadfinder calls it own next
method.
Composer merges an array of middlewares
into own middleware.
To present a default 404
if a route was not found it is possible to do this:
composer = require 'composer'
router = pfadfinder()
notFound = (req, res) ->
res.writeHead 404
res.end 'not found'
composition = composer [router.middleware, notFound]
server = http.createServer composition
server.listen 8888