mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-10-27 06:15:15 +00:00
Rename middleware.ts to proxy.ts per the new Next.js 16 file convention. Fixes the deprecated middleware warning during dev. No behavior change.
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { type NextRequest, NextResponse } from "next/server"
|
|
import { consoleOrigin } from "./console-origin"
|
|
|
|
const RENAMED_PATHS = new Map([
|
|
["/auth/connect", "/auth/connect"],
|
|
["/auth/agent-connect", "/auth/connect"],
|
|
])
|
|
|
|
const SAME_PATHS = ["/login", "/oauth/consent", "/org/invite/"]
|
|
|
|
// Machine callers (plugins, OAuth clients, invites) get an instant 308 with the query intact; humans get the notice page.
|
|
export default function proxy(request: NextRequest) {
|
|
const url = request.nextUrl
|
|
const forwarded =
|
|
process.env.NODE_ENV !== "production"
|
|
? request.headers.get("x-forwarded-host")
|
|
: null
|
|
const console = consoleOrigin(forwarded ?? url.hostname, url.protocol)
|
|
|
|
const renamed = RENAMED_PATHS.get(url.pathname)
|
|
const same = SAME_PATHS.some(
|
|
(p) => url.pathname === p || url.pathname.startsWith(p),
|
|
)
|
|
const target = renamed ?? (same ? url.pathname : null)
|
|
if (target) {
|
|
return NextResponse.redirect(`${console}${target}${url.search}`, 308)
|
|
}
|
|
|
|
if (url.pathname !== "/") {
|
|
return NextResponse.rewrite(new URL("/", url))
|
|
}
|
|
return NextResponse.next()
|
|
}
|
|
|
|
export const config = {
|
|
matcher: [
|
|
"/((?!_next/static|_next/image|favicon.ico|favicon-16x16.png|favicon-32x32.png|apple-touch-icon.png|android-chrome-192x192.png|android-chrome-512x512.png|site.webmanifest|OG.png|logo-fullmark.svg|logo-light-fullmark.svg|icon.png|opengraph-image.png).*)",
|
|
],
|
|
}
|