2025-03-17 20:25:02 -04:00

13 lines
418 B
TypeScript

import { NextRequest, NextResponse } from "next/server"
export const config = {
matcher: ["/api/:path*"],
}
export function middleware(request: NextRequest) {
if (!process.env.API_HOST) {
throw new Error("env variable \"API_HOST\" is not set")
}
const url = new URL(process.env.API_HOST + request.nextUrl.pathname.replace(/^\/api/, '') + request.nextUrl.search)
return NextResponse.rewrite(url, { request })
}