Skip to content

Commit

Permalink
Allow disabling of the dot rule
Browse files Browse the repository at this point in the history
  • Loading branch information
bripkens committed Aug 7, 2016
1 parent a43ea08 commit ee86111
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## Unreleased
- Allow disabling of the `.` (DOT) rule via the `disableDotRule` option.

## v1.2.0
- Support definition of custom HTML `Accept` header values. Contributed by @cgmartin.

Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ message to the user.

This tiny middleware addresses some of the issues. Specifically, it will change
the requested location to the index you specify (default being `/index.html`)
whenever there is a request which fulfils the following criteria:
whenever there is a request which fulfills the following criteria:

1. The request is a GET request
2. which accepts `text/html`,
Expand Down Expand Up @@ -134,3 +134,14 @@ history({
htmlAcceptHeaders: ['text/html', 'application/xhtml+xml']
})
```

### disableDotRule
Disables the dot rule mentioned above:

> [] is not a direct file request, i.e. the requested path does not contain a `.` (DOT) character []
```javascript
history({
disableDotRule: true
})
```
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ exports = module.exports = function historyApiFallback(options) {
}
}

if (parsedUrl.pathname.indexOf('.') !== -1) {
if (parsedUrl.pathname.indexOf('.') !== -1 &&
options.disableDotRule !== true) {
logger(
'Not rewriting',
req.method,
Expand Down
13 changes: 13 additions & 0 deletions test/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ tests['should ignore file requests'] = function(test) {
};


tests['should rewrite requests when the . rule is disabled'] = function(test) {
req.url = 'js/app.js';
middleware = historyApiFallback({
disableDotRule: true
});
middleware(req, null, next);

test.equal(req.url, '/index.html');
test.ok(next.called);
test.done();
};


tests['should take JSON preference into account'] = function(test) {
req.headers.accept = 'application/json, text/plain, */*';

Expand Down

0 comments on commit ee86111

Please sign in to comment.