-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rerouting): check that the new route is different (#8648)
* fix(rerouting): check that the new route is different * add tests * changeset grammar
- Loading branch information
Showing
22 changed files
with
152 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Fixed an issue where a response with status code 404 led to an endless loop of implicit rerouting in dev mode. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { expect } from 'chai'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
for (const caseNumber of [ 1, 2, 3, 4 ]) { | ||
describe(`Custom 404 with implicit rerouting - Case #${caseNumber}`, () => { | ||
/** @type Awaited<ReturnType<typeof loadFixture>> */ | ||
let fixture; | ||
/** @type Awaited<ReturnType<typeof fixture['startDevServer']>> */ | ||
let devServer | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: `./fixtures/custom-404-loop-case-${caseNumber}/`, | ||
site: 'http://example.com' | ||
}); | ||
|
||
devServer = await fixture.startDevServer(); | ||
}); | ||
|
||
// sanity check | ||
it('dev server handles normal requests', async () => { | ||
const resPromise = fixture.fetch('/'); | ||
const result = await withTimeout(resPromise, 1000); | ||
expect(result).to.not.equal(timeout); | ||
expect(result.status).to.equal(200); | ||
}); | ||
|
||
it('dev server stays responsive', async () => { | ||
const resPromise = fixture.fetch('/alvsibdlvjks'); | ||
const result = await withTimeout(resPromise, 1000); | ||
expect(result).to.not.equal(timeout); | ||
expect(result.status).to.equal(404); | ||
}); | ||
|
||
after(async () => { | ||
await devServer.stop(); | ||
}); | ||
}); | ||
} | ||
|
||
|
||
/***** UTILITY FUNCTIONS *****/ | ||
|
||
const timeout = Symbol("timeout") | ||
|
||
/** @template Res */ | ||
function withTimeout( | ||
/** @type Promise<Res> */ | ||
responsePromise, | ||
/** @type number */ | ||
timeLimit | ||
) { | ||
/** @type Promise<typeof timeout> */ | ||
const timeoutPromise = new Promise(resolve => setTimeout(() => resolve(timeout), timeLimit)) | ||
|
||
return Promise.race([ responsePromise, timeoutPromise ]); | ||
} |
1 change: 1 addition & 0 deletions
1
packages/astro/test/fixtures/custom-404-loop-case-1/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default {} |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/custom-404-loop-case-1/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@test/custom-404-loop-case-1", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/astro/test/fixtures/custom-404-loop-case-1/src/pages/404.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
Astro.response.status = 404 | ||
--- | ||
<p>four oh four route</p> |
1 change: 1 addition & 0 deletions
1
packages/astro/test/fixtures/custom-404-loop-case-1/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p>all good here... or is it?</p> |
1 change: 1 addition & 0 deletions
1
packages/astro/test/fixtures/custom-404-loop-case-2/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default {} |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/custom-404-loop-case-2/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@test/custom-404-loop-case-2", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/astro/test/fixtures/custom-404-loop-case-2/src/pages/404.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
return new Response(null, { status: 404 }) | ||
--- | ||
<p>four oh four route</p> |
1 change: 1 addition & 0 deletions
1
packages/astro/test/fixtures/custom-404-loop-case-2/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p>all good here... or is it?</p> |
1 change: 1 addition & 0 deletions
1
packages/astro/test/fixtures/custom-404-loop-case-3/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default {} |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/custom-404-loop-case-3/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@test/custom-404-loop-case-3", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/astro/test/fixtures/custom-404-loop-case-3/src/middleware.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export async function onRequest(ctx, next) { | ||
if (ctx.url.pathname !== '/') { | ||
const response = await next() | ||
return new Response(response.body, { ...response, status: 404 }) | ||
} | ||
return next(); | ||
} |
1 change: 1 addition & 0 deletions
1
packages/astro/test/fixtures/custom-404-loop-case-3/src/pages/404.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p>four oh four route</p> |
1 change: 1 addition & 0 deletions
1
packages/astro/test/fixtures/custom-404-loop-case-3/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p>all good here... or is it?</p> |
1 change: 1 addition & 0 deletions
1
packages/astro/test/fixtures/custom-404-loop-case-4/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default {} |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/custom-404-loop-case-4/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@test/custom-404-loop-case-4", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/astro/test/fixtures/custom-404-loop-case-4/src/middleware.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export function onRequest(ctx, next) { | ||
if (ctx.url.pathname !== '/') { | ||
return new Response(null, { status: 404 }); | ||
} | ||
return next(); | ||
} |
1 change: 1 addition & 0 deletions
1
packages/astro/test/fixtures/custom-404-loop-case-4/src/pages/404.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p>four oh four route</p> |
1 change: 1 addition & 0 deletions
1
packages/astro/test/fixtures/custom-404-loop-case-4/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p>all good here... or is it?</p> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.