Files
pse.dev/middleware.ts
Kalidou Diagne 3212810096 feat: add basic tests
This PR adds basic tests to ensure functionality doesn't break with new features

fix search/route

fix test issues

fix errrors

fix tests

fix issue

fix config

add js-yaml

fix vercel config and update ci

fix vercel config

fix vercel config

fix vercel config

fix config for vercel

update config vitest

fix vercel tests

fix: fix tests vercel issues

fix: remove --frozen-lockfile flag from CI/CD to allow lockfile updates

fix: update dependencies and lockfile to resolve CI/CD issues

fix: import beforeAll and afterAll from vitest in setup file
2025-08-07 22:46:25 +01:00

52 lines
1.2 KiB
TypeScript

import { NextResponse } from "next/server"
import type { NextRequest } from "next/server"
// List of previous supported language
const LANGUAGE_CODES = ["en", "it", "de", "es", "fr", "ja", "ko"]
export function middleware(request: NextRequest) {
const { pathname } = request.nextUrl
if (LANGUAGE_CODES.includes(pathname.slice(1))) {
return NextResponse.redirect(new URL("/", request.url))
}
const languageCode = LANGUAGE_CODES.find((code) =>
pathname.startsWith(`/${code}/`)
)
if (languageCode) {
const newPathname = pathname.replace(`/${languageCode}`, "")
const newUrl = new URL(newPathname, request.url)
request.nextUrl.searchParams.forEach((value, key) => {
newUrl.searchParams.set(key, value)
})
return NextResponse.redirect(newUrl)
}
return NextResponse.next()
}
export const config = {
matcher: [
// Match exact language codes (e.g., /en, /fr)
"/en",
"/it",
"/de",
"/es",
"/fr",
"/ja",
"/ko",
// Match all paths that start with any of the language codes
"/en/:path*",
"/it/:path*",
"/de/:path*",
"/es/:path*",
"/fr/:path*",
"/ja/:path*",
"/ko/:path*",
],
}