| 12345678910111213141516171819202122232425262728293031 |
- import type { NextConfig } from "next";
- import createNextIntlPlugin from "next-intl/plugin";
- /** 开发时代理真实后端,避免浏览器直连局域网 IP 时的 CORS。与 .env.development 中 API_PROXY_TARGET 一致。 */
- const apiProxyTarget =
- process.env.API_PROXY_TARGET?.replace(/\/$/, "") ?? "";
- const remittanceProxyTarget =
- process.env.API_PROXY_TARGET_REMITTANCE?.replace(/\/$/, "") ?? "";
- const nextConfig: NextConfig = {
- async rewrites() {
- const rewrites = [];
- if (apiProxyTarget && /^https?:\/\//i.test(apiProxyTarget)) {
- rewrites.push({
- source: "/api-backend/:path*",
- destination: `${apiProxyTarget}/:path*`,
- });
- }
- if (remittanceProxyTarget && /^https?:\/\//i.test(remittanceProxyTarget)) {
- rewrites.push({
- source: "/api-backend-remittance/:path*",
- destination: `${remittanceProxyTarget}/:path*`,
- });
- }
- return rewrites;
- },
- };
- const withNextIntl = createNextIntlPlugin("./src/i18n/request.ts");
- export default withNextIntl(nextConfig);
|