Skip to content

Commit

Permalink
support for params
Browse files Browse the repository at this point in the history
  • Loading branch information
palanik committed Feb 10, 2017
1 parent cd05cea commit fc15703
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,8 @@
"isparta": "^4.0.0",
"mocha": "^3.2.0",
"node-mocks-http": "^1.5.6"
},
"dependencies": {
"path-to-regexp": "^1.7.0"
}
}
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import pathToRegexp from 'path-to-regexp';

export default
function redirector(...args) {
const path = (args.length < 2) ? args[0] : args[1];
const status = (args.length > 1) ? args[0] : 302;

return function redirect(req, res) {
res.redirect(status, path);
res.redirect(status, pathToRegexp.compile(path)(req.params));
};
}

Expand Down

0 comments on commit fc15703

Please sign in to comment.