13 lines
418 B
TypeScript
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 })
|
|
} |