-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmiddleware.ts
27 lines (23 loc) · 1010 Bytes
/
middleware.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { NextMiddleware, NextRequest, NextResponse } from 'next/server';
// Next.js middleware
// ==================
// https://nextjs.org/docs/middleware
export const middleware: NextMiddleware = ( req: NextRequest ) => {
// Remove x-middleware-prefetch header to prevent VIP's infrastructure
// from caching empty JSON responses on prefetched data for SSR pages. See the following URLs for more info:
// https://github.com/vercel/next.js/discussions/45997
// https://github.com/vercel/next.js/pull/45772
// https://github.com/vercel/next.js/blob/v13.1.1/packages/next/server/base-server.ts#L1069
const headers = new Headers(req.headers);
headers.delete('x-middleware-prefetch');
// Required health check endpoint on VIP. Do not remove.
if ( req.nextUrl.pathname === '/cache-healthcheck' ) {
return NextResponse.rewrite( new URL( '/api/healthcheck', req.url ) );
}
// Continue as normal through the Next.js lifecycle.
return NextResponse.next({
request: {
headers,
},
});
}