mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-11 04:22:13 +00:00
[now-routing-utils][now-build-utils] Refactor zero-config rewrites (#3832)
This PR refactors the rewrites (the dynamic routes as well as the route that prevents directory listing for zero config deployments) so they are not in the `handle: miss` phase. This is necessary because the behavior of `handle: miss` will change in an upcoming release. The solution is to separate these into `rewriteRoutes` that can then be merged properly with the user's routes. They will be appended to the `handle: filesystem` phase (or add the phase if it doesn't exist).
This commit is contained in:
@@ -411,28 +411,6 @@ test(
|
||||
})
|
||||
);
|
||||
|
||||
test(
|
||||
'[now dev] does not display directory listing after multiple 404',
|
||||
testFixtureStdio('handle-miss-multiple-404', async (t, port) => {
|
||||
t.is((await fetch(`http://localhost:${port}/pathA/dir`)).status, 404);
|
||||
t.is((await fetch(`http://localhost:${port}/pathB/dir`)).status, 404);
|
||||
t.is((await fetch(`http://localhost:${port}/pathC/dir`)).status, 200);
|
||||
})
|
||||
);
|
||||
|
||||
test(
|
||||
'[now dev] does not display directory listing after `handle: miss` and 404',
|
||||
testFixtureStdio('handle-miss-handle-filesystem-404', async (t, port) => {
|
||||
t.is((await fetch(`http://localhost:${port}/pathA/dir`)).status, 404);
|
||||
t.is((await fetch(`http://localhost:${port}/pathB/dir`)).status, 404);
|
||||
t.is((await fetch(`http://localhost:${port}/pathC/dir`)).status, 200);
|
||||
|
||||
t.is((await fetch(`http://localhost:${port}/pathA/dir/one`)).status, 200);
|
||||
t.is((await fetch(`http://localhost:${port}/pathB/dir/two`)).status, 200);
|
||||
t.is((await fetch(`http://localhost:${port}/pathC/dir/three`)).status, 200);
|
||||
})
|
||||
);
|
||||
|
||||
test(
|
||||
'[now dev] handles hit after handle: filesystem',
|
||||
testFixtureStdio('handle-hit-after-fs', async (t, port) => {
|
||||
@@ -606,6 +584,31 @@ test('[now dev] validate env var names', async t => {
|
||||
t.pass();
|
||||
});
|
||||
|
||||
test(
|
||||
'[now dev] test rewrites with segments serve correct content',
|
||||
testFixtureStdio('test-rewrites-with-segments', async (t, port) => {
|
||||
const users = await fetchWithRetry(
|
||||
`http://localhost:${port}/api/users/first`,
|
||||
3
|
||||
);
|
||||
t.regex(await users.text(), /first/gm);
|
||||
const fourtytwo = await fetchWithRetry(
|
||||
`http://localhost:${port}/api/fourty-two`,
|
||||
3
|
||||
);
|
||||
t.regex(await fourtytwo.text(), /42/gm);
|
||||
const rand = await fetchWithRetry(`http://localhost:${port}/rand`, 3);
|
||||
t.regex(await rand.text(), /42/gm);
|
||||
const dynamic = await fetchWithRetry(
|
||||
`http://localhost:${port}/api/dynamic`,
|
||||
3
|
||||
);
|
||||
t.regex(await dynamic.text(), /dynamic/gm);
|
||||
const notfound = await fetch(`http://localhost:${port}/api`);
|
||||
t.is(notfound.status, 404);
|
||||
})
|
||||
);
|
||||
|
||||
test(
|
||||
'[now dev] test rewrites serve correct content',
|
||||
testFixtureStdio('test-rewrites', async (t, port) => {
|
||||
|
||||
Reference in New Issue
Block a user