Skip to content

Instantly share code, notes, and snippets.

@lsongdev
Last active February 16, 2016 06:36
Show Gist options
  • Save lsongdev/366da1168b0a18df8c0f to your computer and use it in GitHub Desktop.
Save lsongdev/366da1168b0a18df8c0f to your computer and use it in GitHub Desktop.
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