Skip to content

Commit 0576dfb

Browse files
committed
improve: catch-all route handler config
1 parent 7930faa commit 0576dfb

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import { logError } from '@/lib/clients/logger'
99
import { NextRequest } from 'next/server'
1010

1111
export const revalidate = 1800
12-
export const dynamic = 'force-static'
12+
export const runtime = 'edge'
13+
14+
const REVALIDATE_TIME = 1800 // 30 minutes ttl
1315

1416
export async function GET(request: NextRequest): Promise<Response> {
1517
const url = new URL(request.url)
@@ -52,12 +54,15 @@ export async function GET(request: NextRequest): Promise<Response> {
5254
}
5355

5456
try {
57+
const headers = new Headers(request.headers)
58+
headers.delete('host') // prevent host header conflicts
59+
5560
const res = await fetch(url.toString(), {
56-
headers: new Headers(request.headers),
61+
headers,
5762
redirect: 'follow',
5863
cache: 'force-cache',
5964
next: {
60-
revalidate: 1800,
65+
revalidate: REVALIDATE_TIME,
6166
},
6267
})
6368

@@ -75,7 +80,7 @@ export async function GET(request: NextRequest): Promise<Response> {
7580
if (!newHeaders.has('cache-control')) {
7681
newHeaders.set(
7782
'cache-control',
78-
'public, max-age=1800, s-maxage=1800, stale-while-revalidate=86400'
83+
`public, max-age=${REVALIDATE_TIME}, s-maxage=${REVALIDATE_TIME}, stale-while-revalidate=86400`
7984
)
8085
}
8186

0 commit comments

Comments
 (0)