-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
30 lines (26 loc) · 1.06 KB
/
Copy pathproxy.ts
File metadata and controls
30 lines (26 loc) · 1.06 KB
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
28
29
30
import { NextResponse, type NextRequest } from 'next/server';
import { isProduction } from '@/lib/seo/env';
/**
* Environment isolation at the edge of the app.
*
* In Next.js 16 "middleware" was renamed to "proxy" (it runs in the Node.js
* runtime, ahead of your app). This file is the Next.js 16 equivalent of the
* `middleware.ts` the spec describes.
*
* Responsibility: any NON-production deployment (preview/staging) gets
* `X-Robots-Tag: noindex, nofollow` on every response, so a preview URL can
* never be indexed even if it is publicly reachable. The check reads the live
* environment at request time, so the same build behaves correctly whether it
* is started as production or preview.
*/
export function proxy(_request: NextRequest): NextResponse {
const response = NextResponse.next();
if (!isProduction()) {
response.headers.set('X-Robots-Tag', 'noindex, nofollow');
}
return response;
}
export const config = {
// Run on everything except Next internals and static assets.
matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
};