-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Header Indicating Suspense Cache HIT
- Loading branch information
1 parent
2d55e8f
commit 16ee6d4
Showing
8 changed files
with
96 additions
and
15 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
13 changes: 13 additions & 0 deletions
13
pages-e2e/features/appFetchCache/assets/app/api/cache/route.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,13 @@ | ||
export const runtime = 'edge'; | ||
|
||
export async function GET(request) { | ||
const url = new URL('/api/hello', request.url); | ||
const data = await fetch(url.href, { next: { tags: ['cache'] } }); | ||
|
||
return new Response( | ||
JSON.stringify({ | ||
body: await data.text(), | ||
headers: Object.fromEntries([...data.headers.entries()]), | ||
}), | ||
); | ||
} |
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,23 @@ | ||
import { beforeAll, describe, it } from 'vitest'; | ||
|
||
describe('Simple Pages API Routes', () => { | ||
it('should return a cached fetch response from the suspense cache', async ({ | ||
expect, | ||
}) => { | ||
const initialResp = await fetch(`${DEPLOYMENT_URL}/api/cache`); | ||
const initialRespJson = await initialResp.json(); | ||
|
||
expect(initialRespJson.body).toEqual(expect.stringMatching('Hello world')); | ||
expect(initialRespJson.headers).toEqual( | ||
expect.not.objectContaining({ 'cf-next-suspense-cache': 'HIT' }), | ||
); | ||
|
||
const cachedResp = await fetch(`${DEPLOYMENT_URL}/api/cache`); | ||
const cachedRespJson = await cachedResp.json(); | ||
|
||
expect(cachedRespJson.body).toEqual(expect.stringMatching('Hello world')); | ||
expect(cachedRespJson.headers).toEqual( | ||
expect.objectContaining({ 'cf-next-suspense-cache': 'HIT' }), | ||
); | ||
}); | ||
}); |
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,3 @@ | ||
{ | ||
"setup": "node --loader tsm setup.ts" | ||
} |
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,2 @@ | ||
import { copyWorkspaceAssets } from '../_utils/copyWorkspaceAssets'; | ||
await copyWorkspaceAssets(); |
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
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