mirror of
https://github.com/Lapikud/tipilan.git
synced 2026-09-22 15:22:59 +00:00
Migrate to proxy, remome syslink
This commit is contained in:
42
src/proxy.ts
Normal file
42
src/proxy.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import createMiddleware from "next-intl/middleware";
|
||||
import { NextRequest } from "next/server";
|
||||
import { routing } from "./i18n/routing";
|
||||
|
||||
const handleI18nRouting = createMiddleware(routing);
|
||||
|
||||
export default function proxy(request: NextRequest) {
|
||||
const response = handleI18nRouting(request);
|
||||
|
||||
const location = response.headers.get("location");
|
||||
|
||||
if (location) {
|
||||
const url = new URL(location);
|
||||
|
||||
// Keep localhost development redirects intact. If not then DO NOT!
|
||||
const isLocalhost =
|
||||
url.hostname === "localhost" || url.hostname === "127.0.0.1";
|
||||
|
||||
if (!isLocalhost && url.port === "3000") {
|
||||
url.port = "";
|
||||
response.headers.set("location", url.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
export const config = {
|
||||
// Match only internationalized pathnames
|
||||
matcher: [
|
||||
// Enable a redirect to a matching locale at the root
|
||||
"/",
|
||||
|
||||
// Set a cookie to remember the previous locale for
|
||||
// all requests that have a locale prefix
|
||||
"/(et|en)/:path*",
|
||||
|
||||
// Enable redirects that add missing locales
|
||||
// (e.g. `/pathnames` -> `/en/pathnames`)
|
||||
"/((?!_next|_vercel|.*\\..*).*)",
|
||||
],
|
||||
};
|
||||
Reference in New Issue
Block a user