Skip to content

Commit

Permalink
fix(dev-server): remove search params from the url before matching
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmoy Bhowmik committed Dec 11, 2023
1 parent 7a0bf13 commit f47bfcb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/core/integration-tests/test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,11 @@ describe('server', function () {
assert.equal(await get('/something', port), rootIndex);
assert.equal(await get('/other', port), other);
assert.equal(await get('/foo', port), fooIndex);
assert.equal(await get('/foo?foo=bar', port), fooIndex);
assert.equal(await get('/foo/', port), fooIndex);
assert.equal(await get('/foo/bar', port), fooIndex);
assert.equal(await get('/foo/other', port), fooOther);
assert.equal(await get('/foo/other?foo=bar', port), fooOther);
});

it('should serve a default page if the single HTML bundle is not called index', async function () {
Expand Down
10 changes: 8 additions & 2 deletions packages/reporters/dev-server/src/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ export default class Server {
});

let indexFilePath = null;
let {pathname: reqURL} = url.parse(req.originalUrl || req.url);

if (!reqURL) {
reqURL = '/';
}

if (htmlBundleFilePaths.length === 1) {
indexFilePath = htmlBundleFilePaths[0];
} else {
Expand All @@ -212,11 +218,11 @@ export default class Server {
let matchesIsIndex = null;
if (
isIndex &&
(req.url.startsWith(bundleDirSubdir) || req.url === bundleDir)
(reqURL.startsWith(bundleDirSubdir) || reqURL === bundleDir)
) {
// bundle is /bar/index.html and (/bar or something inside of /bar/** was requested was requested)
matchesIsIndex = true;
} else if (req.url == path.posix.join(bundleDir, withoutExtension)) {
} else if (reqURL == path.posix.join(bundleDir, withoutExtension)) {
// bundle is /bar/foo.html and /bar/foo was requested
matchesIsIndex = false;
}
Expand Down

0 comments on commit f47bfcb

Please sign in to comment.