chore: proxy backend routes via Next rewrites

This commit is contained in:
taDuc
2026-05-10 02:55:45 +07:00
parent b3e765b6f1
commit 0d6599015b
4 changed files with 37 additions and 6 deletions
+29 -1
View File
@@ -19,6 +19,34 @@ const nextConfig: NextConfig = {
],
},
output: 'standalone',
async rewrites() {
// Proxy backend API calls through Next.js to avoid browser CORS issues.
//
// Configure the target via:
// - API_PROXY_TARGET (server-side, recommended) e.g. http://localhost:8080
// - NEXT_PUBLIC_API_URL_ROOT (fallback)
const target =
process.env.API_PROXY_TARGET ||
process.env.NEXT_PUBLIC_API_URL_ROOT ||
"https://history-api.kain.id.vn";
const prefixes = [
"auth",
"users",
"media",
"projects",
"submissions",
"statistics",
"roles",
"historian",
];
return [
...prefixes.map((p) => ({
source: `/${p}/:path*`,
destination: `${target}/${p}/:path*`,
})),
];
},
webpack(config) {
config.module.rules.push({
test: /\.svg$/,
@@ -37,4 +65,4 @@ const nextConfig: NextConfig = {
},
};
export default nextConfig;
export default nextConfig;