NextJS在生产中进行重写

时间:2020-10-14 05:43:43

标签: javascript proxy url-rewriting next.js

我发现重写以代理到开发中的后端服务器:

https://nextjs.org/docs/api-reference/next.config.js/rewrites

rewrites: async () => [
...nextI18NextRewrites(localeSubpaths),
{ source: '/api/:path*', destination: 'http://localhost:8080/:path*' },
],

如果url不是本地主机,这在生产环境中如何工作?

对于目的地,我是否需要添加整个域,还是需要针对开发/生产的单独重写规则?

1 个答案:

答案 0 :(得分:1)

只需从目标中删除域部分,然后使用absolute路径即可。

rewrites: async () => [
  ...nextI18NextRewrites(localeSubpaths),
  { source: '/api/:path*', destination: '/:path*' },
  // ------------------------------------^
];