enzostvs HF Staff commited on
Commit
0cce1b7
·
1 Parent(s): cfa4f4c

do the redirect server-side

Browse files
app/layout.tsx CHANGED
@@ -14,7 +14,6 @@ import TanstackContext from "@/components/contexts/tanstack-query-context";
14
  import { LoginProvider } from "@/components/contexts/login-context";
15
  import { ProProvider } from "@/components/contexts/pro-context";
16
  import { generateSEO, generateStructuredData } from "@/lib/seo";
17
- import DomainRedirect from "@/components/domain-redirect";
18
 
19
  const inter = Inter({
20
  variable: "--font-inter-sans",
@@ -114,7 +113,6 @@ export default async function RootLayout({
114
  data-domain="deepsite.hf.co"
115
  src="https://plausible.io/js/script.js"
116
  />
117
- <DomainRedirect />
118
  <IframeDetector />
119
  <Toaster richColors position="bottom-center" />
120
  <TanstackContext>
 
14
  import { LoginProvider } from "@/components/contexts/login-context";
15
  import { ProProvider } from "@/components/contexts/pro-context";
16
  import { generateSEO, generateStructuredData } from "@/lib/seo";
 
17
 
18
  const inter = Inter({
19
  variable: "--font-inter-sans",
 
113
  data-domain="deepsite.hf.co"
114
  src="https://plausible.io/js/script.js"
115
  />
 
116
  <IframeDetector />
117
  <Toaster richColors position="bottom-center" />
118
  <TanstackContext>
components/domain-redirect/index.tsx DELETED
@@ -1,23 +0,0 @@
1
- "use client";
2
-
3
- import { useEffect } from "react";
4
-
5
- export default function DomainRedirect() {
6
- useEffect(() => {
7
- if (typeof window === "undefined") return;
8
-
9
- const host = window.location.host;
10
-
11
- // Check if we're not on hf.co or huggingface.co
12
- const isHfCo = host === "hf.co" || host.startsWith("hf.co:");
13
- const isHuggingFaceCo =
14
- host === "huggingface.co" || host.startsWith("huggingface.co:");
15
-
16
- if (!isHfCo && !isHuggingFaceCo) {
17
- // Redirect to the correct URL
18
- window.location.replace("https://huggingface.co/deepsite");
19
- }
20
- }, []);
21
-
22
- return null;
23
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
middleware.ts CHANGED
@@ -2,6 +2,17 @@ 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
 
 
2
  import type { NextRequest } from "next/server";
3
 
4
  export function middleware(request: NextRequest) {
5
+ const host = request.headers.get("host") || "";
6
+
7
+ // Check if we're not on hf.co or huggingface.co
8
+ const isHfCo = host === "hf.co" || host.startsWith("hf.co:");
9
+ const isHuggingFaceCo = host === "huggingface.co" || host.startsWith("huggingface.co:");
10
+
11
+ if (!isHfCo && !isHuggingFaceCo) {
12
+ // Server-side redirect to the correct URL
13
+ return NextResponse.redirect("https://huggingface.co/deepsite", 301);
14
+ }
15
+
16
  const headers = new Headers(request.headers);
17
  headers.set("x-current-host", request.nextUrl.host);
18