Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX[dev-server]: Fix html file matching from URL #9347

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like previously it only looked at req.url, is there a reason why you added originalUrl?

I remember that we had problems with req.originalUrl in the past if you use the proxy in front of the dev server.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanted to make sure we are using the same pathname everywhere like here.


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