Skip to content

Commit

Permalink
HTML bundle serving bug. (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
ry authored and devongovett committed Mar 22, 2018
1 parent 01e7c44 commit 43cab32
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ function middleware(bundler) {
function respond() {
if (bundler.errored) {
return send500();
} else if (!req.url.startsWith(bundler.options.publicURL)) {
// If the URL doesn't start with the public path, send the main HTML bundle
} else if (
!req.url.startsWith(bundler.options.publicURL) ||
path.extname(req.url) === ''
) {
// 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
Expand Down
14 changes: 14 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,18 @@ describe('server', function() {
let data = await get('/dist/index.js', https);
assert.equal(data, fs.readFileSync(__dirname + '/dist/index.js', 'utf8'));
});

it('should serve static assets as well as html', async function() {
let b = bundler(__dirname + '/integration/html/index.html', {
publicUrl: '/'
});
server = await b.serve(0);
// When accessing / we should get the index page.
let data = await get('/');
assert.equal(data, fs.readFileSync(__dirname + '/dist/index.html', 'utf8'));
// When accessing /hello.txt we should get txt document.
fs.writeFileSync(__dirname + '/dist/hello.txt', 'hello');
data = await get('/hello.txt');
assert.equal(data, 'hello');
});
});

0 comments on commit 43cab32

Please sign in to comment.