Spaces:
Running
Running
do it through proxy
Browse files- middleware.ts +0 -9
- proxy.ts +26 -0
middleware.ts
CHANGED
|
@@ -2,15 +2,6 @@ import { NextResponse } from "next/server";
|
|
| 2 |
import type { NextRequest } from "next/server";
|
| 3 |
|
| 4 |
export function middleware(request: NextRequest) {
|
| 5 |
-
const host = request.headers.get("host") || "";
|
| 6 |
-
|
| 7 |
-
const isLocalhost = host.startsWith("localhost") || host.startsWith("127.0.0.1");
|
| 8 |
-
const isCorrectDomain = host === "huggingface.co" || host.startsWith("huggingface.co:");
|
| 9 |
-
|
| 10 |
-
if (!isCorrectDomain && !isLocalhost) {
|
| 11 |
-
return NextResponse.redirect(new URL("https://huggingface.co/deepsite"), 301);
|
| 12 |
-
}
|
| 13 |
-
|
| 14 |
const headers = new Headers(request.headers);
|
| 15 |
headers.set("x-current-host", request.nextUrl.host);
|
| 16 |
|
|
|
|
| 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 |
|
proxy.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { NextResponse } from "next/server";
|
| 2 |
+
import type { NextRequest } from "next/server";
|
| 3 |
+
|
| 4 |
+
export function proxy(request: NextRequest) {
|
| 5 |
+
const hostname = request.headers.get("host") || "";
|
| 6 |
+
|
| 7 |
+
// Don't redirect if on localhost
|
| 8 |
+
if (hostname.includes("localhost") || hostname.includes("127.0.0.1")) {
|
| 9 |
+
return NextResponse.next();
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
// Check if user is on hf.co or huggingface.co domains
|
| 13 |
+
const isHuggingFace = hostname.includes("hf.co") || hostname.includes("huggingface.co");
|
| 14 |
+
|
| 15 |
+
// If not on HuggingFace domains, redirect to huggingface.co/deepsite
|
| 16 |
+
if (!isHuggingFace) {
|
| 17 |
+
return NextResponse.redirect("https://huggingface.co/deepsite", 301);
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
// Continue normally for HuggingFace domains
|
| 21 |
+
return NextResponse.next();
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
export const config = {
|
| 25 |
+
matcher: "/:path*", // Match all paths
|
| 26 |
+
};
|