diff --git a/runtime/src/server/middleware/index.ts b/runtime/src/server/middleware/index.ts index 96fd9ea05..823b1aaa8 100644 --- a/runtime/src/server/middleware/index.ts +++ b/runtime/src/server/middleware/index.ts @@ -121,8 +121,14 @@ export function serve({ prefix, pathname, cache_control }: { res.setHeader('Cache-Control', cache_control); res.end(data); } catch (err) { - res.statusCode = 404; - res.end('not found'); + // [#1442](https://github.com/sveltejs/sapper/issues/1142) + // Requests to addresses under "/client" cannot be filtered out on their prefix, and can therefore end up here. + if (req.path.startsWith(prefix) && !/\..*$/.test(req.path)) { + next(); + } else { + res.statusCode = 404; + res.end('not found'); + } } } else { next(); diff --git a/test/apps/basics/src/routes/apple/new.svelte b/test/apps/basics/src/routes/apple/new.svelte new file mode 100644 index 000000000..a9d787cc5 --- /dev/null +++ b/test/apps/basics/src/routes/apple/new.svelte @@ -0,0 +1 @@ +Success. diff --git a/test/apps/basics/src/routes/client/client/new.svelte b/test/apps/basics/src/routes/client/client/new.svelte new file mode 100644 index 000000000..ef8e05020 --- /dev/null +++ b/test/apps/basics/src/routes/client/client/new.svelte @@ -0,0 +1 @@ +

Success.

diff --git a/test/apps/basics/src/routes/client/index.svelte b/test/apps/basics/src/routes/client/index.svelte new file mode 100644 index 000000000..ef8e05020 --- /dev/null +++ b/test/apps/basics/src/routes/client/index.svelte @@ -0,0 +1 @@ +

Success.

diff --git a/test/apps/basics/src/routes/client/new.svelte b/test/apps/basics/src/routes/client/new.svelte new file mode 100644 index 000000000..ef8e05020 --- /dev/null +++ b/test/apps/basics/src/routes/client/new.svelte @@ -0,0 +1 @@ +

Success.

diff --git a/test/apps/basics/test.ts b/test/apps/basics/test.ts index f1313b81a..9467bfb95 100644 --- a/test/apps/basics/test.ts +++ b/test/apps/basics/test.ts @@ -383,6 +383,15 @@ describe('basics', function() { assert.equal(await r.text('h2'), 'Called 1 time'); }); + it('finds routes under /client/', async () => { + await r.load('/client'); + assert.equal(await r.text('h1'), 'Success.'); + await r.load('/client/new'); + assert.equal(await r.text('h1'), 'Success.'); + await r.load('/client/client/new'); + assert.equal(await r.text('h1'), 'Success.'); + }); + it('survives the tests with no server errors', () => { assert.deepEqual(r.errors, []); });