-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
30 lines (23 loc) · 911 Bytes
/
middleware.ts
File metadata and controls
30 lines (23 loc) · 911 Bytes
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 } from "next/server";
import type { NextRequest } from "next/server";
export function middleware(request: NextRequest) {
const requestHeaders = new Headers(request.headers);
if (!requestHeaders.get("x-request-id")) {
requestHeaders.set("x-request-id", crypto.randomUUID());
}
// Only apply to embed routes
if (request.nextUrl.pathname.startsWith("/embed/")) {
const response = NextResponse.next({
request: { headers: requestHeaders },
});
// Set X-Frame-Options to allow embedding from any origin
response.headers.set("X-Frame-Options", "ALLOWALL");
// Set Content Security Policy to allow embedding from any origin
response.headers.set("Content-Security-Policy", "frame-ancestors *");
return response;
}
return NextResponse.next({ request: { headers: requestHeaders } });
}
export const config = {
matcher: "/embed/:path*",
};