Permalink
Browse files

Fix: Wildcard matching results in problems with frameworks that appen…

…d */* to JSON requests.
  • Loading branch information...
1 parent d315172 commit ac8d3d94d50adcdf62f5629f6690c809619982f0 @bripkens committed Jul 16, 2013
Showing with 15 additions and 0 deletions.
  1. +4 −0 lib/index.js
  2. +11 −0 test/rewrites.js
View
4 lib/index.js
@@ -16,6 +16,10 @@ exports = module.exports = function historyApiFallback (req, res, next) {
logger('Not rewriting %s %s because the method is not GET.',
req.method, req.url);
return next();
+ } else if (headers.accept.indexOf('application/json') === 0) {
+ logger('Not rewriting %s %s because the client prefers JSON.',
+ req.method, req.url);
+ return next();
} else if (!acceptsHtml(headers.accept)) {
logger('Not rewriting %s %s because the client does not accept HTML.',
req.method, req.url);
View
11 test/rewrites.js
@@ -60,6 +60,17 @@ tests['should ignore file requests'] = function (test) {
};
+tests['should take JSON preference into account'] = function (test) {
+ req.headers.accept = 'application/json, text/plain, */*';
+
+ historyApiFallback(req, null, next);
+
+ test.equal(req.url, requestedUrl);
+ test.ok(nextCalled);
+ test.done();
+};
+
+
tests['should rewrite valid requests'] = function (test) {
historyApiFallback(req, null, next);

0 comments on commit ac8d3d9

Please sign in to comment.