From 75e8d2b7b2178f4734f6624445c45554d8fb664a Mon Sep 17 00:00:00 2001 From: rhpidfyre <brandon@rhpidfyre.io> Date: Sun, 16 Mar 2025 16:33:16 -0400 Subject: [PATCH] middleware --- web/next.config.ts | 10 +--------- web/src/app/middleware.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 web/src/app/middleware.ts diff --git a/web/next.config.ts b/web/next.config.ts index ece2de4..4d4174c 100644 --- a/web/next.config.ts +++ b/web/next.config.ts @@ -3,15 +3,7 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { distDir: "build", output: "standalone", - rewrites: async () => { - return [ - { - source: "/api/:path*", - destination: "http://localhost:8082/v1/:path*" - } - ] - }, - images: { + images: { remotePatterns: [ { protocol: 'https', diff --git a/web/src/app/middleware.ts b/web/src/app/middleware.ts new file mode 100644 index 0000000..15f7bb5 --- /dev/null +++ b/web/src/app/middleware.ts @@ -0,0 +1,13 @@ +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 + request.nextUrl.search) + return NextResponse.rewrite(url, { request }) +} \ No newline at end of file