Last active
February 16, 2016 06:36
-
-
Save lsongdev/366da1168b0a18df8c0f to your computer and use it in GitHub Desktop.
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
const pathToRegexp = require('path-to-regexp'); | |
function route(def, callback){ | |
var keys = []; | |
var re = pathToRegexp(def, keys); | |
return function(req, res, next){ | |
if(re.test(req.url)){ | |
req.params = {}; | |
var matchs = re.exec(req.url); | |
keys.forEach(function(key, i){ | |
req.params[ key.name ] = matchs[ i + 1 ]; | |
}); | |
callback.apply(this, arguments); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment