Last active
December 20, 2015 19:09
-
-
Save davidchambers/6180729 to your computer and use it in GitHub Desktop.
Express routing using regular expressions with named capturing groups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
express = require 'express' | |
app = express() | |
app.param (name, arg) -> switch Object::toString.call arg | |
when '[object RegExp]' | |
(req, res, next, val) -> | |
if arg.test val then next() else next 'route' | |
app.param 'id', /^\d+$/ | |
app.get '/things/:id', (req, res) -> res.send req.params.id | |
app.listen 8000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment