Skip to content

Commit

Permalink
Recommend absolute paths for rewrite targets (#59)
Browse files Browse the repository at this point in the history
Fixes #58.
  • Loading branch information
helfi92 authored and bripkens committed Jan 8, 2019
1 parent a09b9e0 commit e931cce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,8 @@
# Changelog

## v1.5.1
- Recommend absolute paths for rewrite targets. Contributed by @helfi92.

## v1.5.0
- Expose the HTTP request object in rewrite rules. Contributed by @VladShcherbin.

Expand Down
11 changes: 11 additions & 0 deletions lib/index.js
Expand Up @@ -50,6 +50,17 @@ exports = module.exports = function historyApiFallback(options) {
var match = parsedUrl.pathname.match(rewrite.from);
if (match !== null) {
rewriteTarget = evaluateRewriteRule(parsedUrl, match, rewrite.to, req);

if(rewriteTarget.charAt(0) !== '/') {
logger(
'We recommend using an absolute path for the rewrite target.',
'Received a non-absolute rewrite target',
rewriteTarget,
'for URL',
req.url
);
}

logger('Rewriting', req.method, req.url, 'to', rewriteTarget);
req.url = rewriteTarget;
return next();
Expand Down

0 comments on commit e931cce

Please sign in to comment.