Spaces:
Running
Running
update
Browse files- middleware.ts +9 -3
middleware.ts
CHANGED
|
@@ -2,11 +2,17 @@ import { NextResponse } from "next/server";
|
|
| 2 |
import type { NextRequest } from "next/server";
|
| 3 |
|
| 4 |
export function middleware(request: NextRequest) {
|
| 5 |
-
|
| 6 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
const isHuggingFace = hostname === "huggingface.co" || hostname.endsWith(".huggingface.co");
|
| 8 |
|
| 9 |
-
console.log("[Middleware]
|
| 10 |
|
| 11 |
if (!isHuggingFace && !isLocalDev) {
|
| 12 |
console.log("[Middleware] Redirecting to huggingface.co");
|
|
|
|
| 2 |
import type { NextRequest } from "next/server";
|
| 3 |
|
| 4 |
export function middleware(request: NextRequest) {
|
| 5 |
+
// Get the actual hostname from headers (important for proxied environments like HF Spaces)
|
| 6 |
+
const forwardedHost = request.headers.get("x-forwarded-host");
|
| 7 |
+
const host = request.headers.get("host");
|
| 8 |
+
const hostname = forwardedHost || host || request.nextUrl.hostname;
|
| 9 |
+
|
| 10 |
+
console.log("[Middleware] x-forwarded-host:", forwardedHost, "host:", host, "hostname:", hostname);
|
| 11 |
+
|
| 12 |
+
const isLocalDev = hostname === "localhost" || hostname === "127.0.0.1" || hostname.startsWith("localhost:") || hostname.startsWith("127.0.0.1:");
|
| 13 |
const isHuggingFace = hostname === "huggingface.co" || hostname.endsWith(".huggingface.co");
|
| 14 |
|
| 15 |
+
console.log("[Middleware] isHuggingFace:", isHuggingFace, "isLocalDev:", isLocalDev);
|
| 16 |
|
| 17 |
if (!isHuggingFace && !isLocalDev) {
|
| 18 |
console.log("[Middleware] Redirecting to huggingface.co");
|