From f7fedaf5b6db565fd01f0ba64aa9db1f70b4b525 Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com> Date: Thu, 8 Jun 2023 21:54:22 +0200 Subject: [PATCH] Serve folder's index when requesting folder without slash (#9066) --- packages/core/integration-tests/test/server.js | 2 +- packages/reporters/dev-server/src/Server.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/core/integration-tests/test/server.js b/packages/core/integration-tests/test/server.js index 2f0b8bafe19..5e17a109d04 100644 --- a/packages/core/integration-tests/test/server.js +++ b/packages/core/integration-tests/test/server.js @@ -176,7 +176,7 @@ describe('server', function () { assert.equal(await get('/', port), rootIndex); assert.equal(await get('/something', port), rootIndex); assert.equal(await get('/other', port), other); - assert.equal(await get('/foo', port), rootIndex); + assert.equal(await get('/foo', 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); diff --git a/packages/reporters/dev-server/src/Server.js b/packages/reporters/dev-server/src/Server.js index 22a5a2b50d4..05c074d8f36 100644 --- a/packages/reporters/dev-server/src/Server.js +++ b/packages/reporters/dev-server/src/Server.js @@ -210,8 +210,11 @@ export default class Server { let isIndex = withoutExtension === 'index'; let matchesIsIndex = null; - if (isIndex && req.url.startsWith(bundleDirSubdir)) { - // bundle is /bar/index.html and something inside of /bar/** was requested + if ( + isIndex && + (req.url.startsWith(bundleDirSubdir) || req.url === 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)) { // bundle is /bar/foo.html and /bar/foo was requested