Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	fix
Browse files- app/layout.tsx +20 -0
- middleware.ts +2 -21
    	
        app/layout.tsx
    CHANGED
    
    | @@ -2,6 +2,8 @@ | |
| 2 | 
             
            import type { Metadata, Viewport } from "next";
         | 
| 3 | 
             
            import { Inter, PT_Sans } from "next/font/google";
         | 
| 4 | 
             
            import Script from "next/script";
         | 
|  | |
|  | |
| 5 |  | 
| 6 | 
             
            import "@/assets/globals.css";
         | 
| 7 | 
             
            import { Toaster } from "@/components/ui/sonner";
         | 
| @@ -74,6 +76,24 @@ export default async function RootLayout({ | |
| 74 | 
             
            }: Readonly<{
         | 
| 75 | 
             
              children: React.ReactNode;
         | 
| 76 | 
             
            }>) {
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 77 | 
             
              // const data = await getMe();
         | 
| 78 |  | 
| 79 | 
             
              // Generate structured data
         | 
|  | |
| 2 | 
             
            import type { Metadata, Viewport } from "next";
         | 
| 3 | 
             
            import { Inter, PT_Sans } from "next/font/google";
         | 
| 4 | 
             
            import Script from "next/script";
         | 
| 5 | 
            +
            import { headers } from "next/headers";
         | 
| 6 | 
            +
            import { redirect } from "next/navigation";
         | 
| 7 |  | 
| 8 | 
             
            import "@/assets/globals.css";
         | 
| 9 | 
             
            import { Toaster } from "@/components/ui/sonner";
         | 
|  | |
| 76 | 
             
            }: Readonly<{
         | 
| 77 | 
             
              children: React.ReactNode;
         | 
| 78 | 
             
            }>) {
         | 
| 79 | 
            +
              // Domain redirect check
         | 
| 80 | 
            +
              const headersList = await headers();
         | 
| 81 | 
            +
              const forwardedHost = headersList.get("x-forwarded-host");
         | 
| 82 | 
            +
              const host = headersList.get("host");
         | 
| 83 | 
            +
              const hostname = (forwardedHost || host || "").split(":")[0];
         | 
| 84 | 
            +
             | 
| 85 | 
            +
              const isLocalDev =
         | 
| 86 | 
            +
                hostname === "localhost" ||
         | 
| 87 | 
            +
                hostname === "127.0.0.1" ||
         | 
| 88 | 
            +
                hostname.startsWith("192.168.");
         | 
| 89 | 
            +
              const isHuggingFace =
         | 
| 90 | 
            +
                hostname === "huggingface.co" || hostname.endsWith(".huggingface.co");
         | 
| 91 | 
            +
             | 
| 92 | 
            +
              if (!isHuggingFace && !isLocalDev) {
         | 
| 93 | 
            +
                const pathname = headersList.get("x-invoke-path") || "/deepsite";
         | 
| 94 | 
            +
                redirect(`https://huggingface.co${pathname}`);
         | 
| 95 | 
            +
              }
         | 
| 96 | 
            +
             | 
| 97 | 
             
              // const data = await getMe();
         | 
| 98 |  | 
| 99 | 
             
              // Generate structured data
         | 
    	
        middleware.ts
    CHANGED
    
    | @@ -1,29 +1,10 @@ | |
| 1 | 
             
            import { NextResponse } from "next/server";
         | 
| 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");
         | 
| 19 | 
            -
                const canonicalUrl = new URL("https://huggingface.co/deepsite");
         | 
| 20 | 
            -
                canonicalUrl.pathname = request.nextUrl.pathname;
         | 
| 21 | 
            -
                canonicalUrl.search = request.nextUrl.search;
         | 
| 22 | 
            -
                return NextResponse.redirect(canonicalUrl, 301);
         | 
| 23 | 
            -
              }
         | 
| 24 | 
            -
              
         | 
| 25 | 
             
              const headers = new Headers(request.headers);
         | 
| 26 | 
             
              headers.set("x-current-host", request.nextUrl.host);
         | 
|  | |
| 27 |  | 
| 28 | 
             
              const response = NextResponse.next({ headers });
         | 
| 29 |  | 
|  | |
| 1 | 
             
            import { NextResponse } from "next/server";
         | 
| 2 | 
             
            import type { NextRequest } from "next/server";
         | 
| 3 |  | 
| 4 | 
            +
            export function middleware(request: NextRequest) {  
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 5 | 
             
              const headers = new Headers(request.headers);
         | 
| 6 | 
             
              headers.set("x-current-host", request.nextUrl.host);
         | 
| 7 | 
            +
              headers.set("x-invoke-path", request.nextUrl.pathname + request.nextUrl.search);
         | 
| 8 |  | 
| 9 | 
             
              const response = NextResponse.next({ headers });
         | 
| 10 |  | 
