refactor: rewrites 로직 미들웨어로 이동

This commit is contained in:
2025-03-17 11:11:21 +09:00
parent 594dbd9fc7
commit 6e3b9aaa37
2 changed files with 19 additions and 11 deletions
+19
View File
@@ -0,0 +1,19 @@
import { NextRequest, NextResponse } from "next/server";
const serverApiUrl =
process.env.NEXT_PUBLIC_SERVER_API_URL ?? "http://localhost:3000";
export function middleware(req: NextRequest) {
const pathname = req.nextUrl.pathname;
if (pathname.startsWith("/server")) {
return NextResponse.rewrite(
`${serverApiUrl}${pathname.replace("/server", "")}`,
);
}
return NextResponse.next();
}
export const config = {
matcher: "/server/:path*",
};
-11
View File
@@ -1,9 +1,6 @@
import type { NextConfig } from "next";
import webpack from "webpack";
const serverApiUrl =
process.env.NEXT_PUBLIC_SERVER_API_URL || "http://localhost:3000";
const nextConfig: NextConfig = {
webpack: (config) => {
config.plugins.push(
@@ -36,14 +33,6 @@ const nextConfig: NextConfig = {
return config;
},
async rewrites() {
return [
{
source: "/server/:path*",
destination: `${serverApiUrl}/:path*`,
},
];
},
};
export default nextConfig;