Repository navigation
Expand file tree
/
Copy pathproxy.ts
More file actions
62 lines (54 loc) · 2.02 KB
/
Copy pathproxy.ts
File metadata and controls
62 lines (54 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import type { NextRequest } from "next/server"
import { NextResponse } from "next/server"
const NOVA_HOSTS = new Set(["nova.supercodeai.tech", "nova.localhost"])
const NOVA_INTERNAL_PATH = "/nova-app-internal"
export function proxy(request: NextRequest) {
const forwardedHost = request.headers.get("x-forwarded-host")?.split(",")[0]
const hostname = (forwardedHost ?? request.headers.get("host") ?? "")
.trim()
.split(":")[0]
.toLowerCase()
const isNovaHost = NOVA_HOSTS.has(hostname)
const path = request.nextUrl.pathname
if (!isNovaHost) {
// Main app host: keep legacy /settings shorthand for the dashboard.
if (path === "/settings" || path.startsWith("/settings/")) {
const url = request.nextUrl.clone()
url.pathname = path === "/settings"
? "/dashboard/settings"
: path.replace(/^\/settings/, "/dashboard/settings")
return NextResponse.redirect(url)
}
if (path.startsWith(NOVA_INTERNAL_PATH)) {
const novaUrl = process.env.NODE_ENV === "development"
? "http://nova.localhost:3003/"
: "https://nova.supercodeai.tech/"
return NextResponse.redirect(new URL(novaUrl))
}
return NextResponse.next()
}
if (path === "/login") return NextResponse.next()
// Nova host: never send users to the dashboard settings surface.
if (path === "/dashboard/settings" || path.startsWith("/dashboard/settings/")) {
const url = request.nextUrl.clone()
url.pathname = "/settings"
url.search = request.nextUrl.search
return NextResponse.redirect(url)
}
const url = request.nextUrl.clone()
if (path === "/") {
url.pathname = NOVA_INTERNAL_PATH
} else if (path === "/app") {
url.pathname = `${NOVA_INTERNAL_PATH}/app`
} else if (path.startsWith(NOVA_INTERNAL_PATH)) {
return NextResponse.next()
} else {
url.pathname = `${NOVA_INTERNAL_PATH}${path}`
}
return NextResponse.rewrite(url)
}
export const config = {
matcher: [
"/((?!api|_next/static|_next/image|favicon.ico|robots.txt|sitemap.xml|.*\\.[^/]+$).*)",
],
}