deepsite / middleware.ts
enzostvs's picture
enzostvs HF Staff
improve SEO
8bce833
raw
history blame
1.04 kB
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
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).*)"],
};