-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproxy.ts
More file actions
36 lines (30 loc) · 1.31 KB
/
Copy pathproxy.ts
File metadata and controls
36 lines (30 loc) · 1.31 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
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
const OLD_DOMAINS = ["devsanantonio.com", "www.devsanantonio.com"];
export function proxy(request: NextRequest) {
const host = request.headers.get("host")?.split(":")[0]; // strip port if present
if (host && OLD_DOMAINS.includes(host)) {
const url = new URL(request.url);
url.hostname = "www.devsa.community";
url.protocol = "https:";
url.port = "";
return NextResponse.redirect(url.toString(), 301); // permanent redirect
}
/**
* Pass the requested path through as a header.
*
* `not-found.tsx` has no other way to know what was asked for: there is no
* server API for the current pathname, and reaching for `usePathname` makes
* the whole 404 a client component — which meant the page server-rendered as
* "Loading..." and only painted the actual 404 after hydration. Echoing the
* failed path is worth keeping; a 404 that needs JavaScript to say anything
* is not.
*/
const headers = new Headers(request.headers);
headers.set("x-pathname", request.nextUrl.pathname);
return NextResponse.next({ request: { headers } });
}
export const config = {
// Run on all routes except Next.js internals and static assets
matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
};