Skip to content

Commit

Permalink
Fix serving files with query params (#1169)
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett authored Apr 11, 2018
1 parent 3b1a585 commit 3435c4c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const generateCertificate = require('./utils/generateCertificate');
const getCertificate = require('./utils/getCertificate');
const logger = require('./Logger');
const path = require('path');
const url = require('url');

serveStatic.mime.define({
'application/wasm': ['wasm']
Expand Down Expand Up @@ -43,18 +44,19 @@ function middleware(bundler) {
}

function respond() {
let {pathname} = url.parse(req.url);
if (bundler.errored) {
return send500();
} else if (
!req.url.startsWith(bundler.options.publicURL) ||
path.extname(req.url) === ''
!pathname.startsWith(bundler.options.publicURL) ||
path.extname(pathname) === ''
) {
// If the URL doesn't start with the public path, or the URL doesn't
// have a file extension, send the main HTML bundle.
return sendIndex();
} else {
// Otherwise, serve the file from the dist folder
req.url = req.url.slice(bundler.options.publicURL.length);
req.url = pathname.slice(bundler.options.publicURL.length);
return serve(req, res, send404);
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,14 @@ describe('server', function() {
data = await get('/hello.txt');
assert.equal(data, 'hello');
});

it('should work with query parameters that contain a dot', async function() {
let b = bundler(__dirname + '/integration/html/index.html', {
publicUrl: '/'
});
server = await b.serve(0);

let data = await get('/?foo=bar.baz');
assert.equal(data, fs.readFileSync(__dirname + '/dist/index.html', 'utf8'));
});
});

0 comments on commit 3435c4c

Please sign in to comment.