Spaces:
Running
Running
File size: 1,246 Bytes
c10f8f8 8bce833 fff976c bff70f1 fff976c 8bce833 c10f8f8 |
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 31 32 33 |
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export function middleware(request: NextRequest) {
const headers = new Headers(request.headers);
headers.set("x-current-host", request.nextUrl.host);
// Create response with headers
const response = NextResponse.next({ headers });
// Add SEO and security headers
// Only set X-Frame-Options for non-HF spaces domains
if (!request.nextUrl.host.includes('hf.space') && !request.nextUrl.host.includes('huggingface.co') && !request.nextUrl.host.includes('hf.co')) {
response.headers.set('X-Frame-Options', 'SAMEORIGIN');
}
response.headers.set('X-Content-Type-Options', 'nosniff');
response.headers.set('Referrer-Policy', 'strict-origin-when-cross-origin');
// Add cache control for better performance
if (request.nextUrl.pathname.startsWith('/_next/static')) {
response.headers.set('Cache-Control', 'public, max-age=31536000, immutable');
}
// Add canonical URL headers for programmatic access
response.headers.set('X-Canonical-URL', `https://deepsite.hf.co${request.nextUrl.pathname}`);
return response;
}
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
};
|