next.config.ts 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. import type { NextConfig } from "next";
  2. import createNextIntlPlugin from "next-intl/plugin";
  3. /** 开发时代理真实后端,避免浏览器直连局域网 IP 时的 CORS。与 .env.development 中 API_PROXY_TARGET 一致。 */
  4. const apiProxyTarget =
  5. process.env.API_PROXY_TARGET?.replace(/\/$/, "") ?? "";
  6. const remittanceProxyTarget =
  7. process.env.API_PROXY_TARGET_REMITTANCE?.replace(/\/$/, "") ?? "";
  8. const nextConfig: NextConfig = {
  9. async rewrites() {
  10. const rewrites = [];
  11. if (apiProxyTarget && /^https?:\/\//i.test(apiProxyTarget)) {
  12. rewrites.push({
  13. source: "/api-backend/:path*",
  14. destination: `${apiProxyTarget}/:path*`,
  15. });
  16. }
  17. if (remittanceProxyTarget && /^https?:\/\//i.test(remittanceProxyTarget)) {
  18. rewrites.push({
  19. source: "/api-backend-remittance/:path*",
  20. destination: `${remittanceProxyTarget}/:path*`,
  21. });
  22. }
  23. return rewrites;
  24. },
  25. };
  26. const withNextIntl = createNextIntlPlugin("./src/i18n/request.ts");
  27. export default withNextIntl(nextConfig);