Skip to content

Commit

Permalink
feat: support non-ascii URL redirects as well
Browse files Browse the repository at this point in the history
  • Loading branch information
manniL committed Aug 24, 2018
1 parent a662891 commit 759e4bf
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
// Creates new middleware using provided options
function create (rules) {
return function redirectRoute (req, res, next) {
const foundRule = rules.find(o => o.from.test(req.url))
const decodedBaseUrl = decodeURI(req.url)
const foundRule = rules.find(o => o.from.test(decodedBaseUrl))

if (!foundRule) {
return next()
}
const toUrl = req.url.replace(foundRule.from, foundRule.to)
const toUrl = decodedBaseUrl.replace(foundRule.from, foundRule.to)

res.statusCode = foundRule.statusCode || 302
res.setHeader('Location', toUrl)
Expand Down

0 comments on commit 759e4bf

Please sign in to comment.