Rya*_*P13 3 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*' },
],
Run Code Online (Sandbox Code Playgroud)
如果 url 不是 localhost,这在生产中如何工作?
对于目的地,我是否需要添加完整的域,或者我是否需要单独的开发/生产重写规则?
只需从目标中删除域部分并使用absolute
路径即可。
rewrites: async () => [
...nextI18NextRewrites(localeSubpaths),
{ source: '/api/:path*', destination: '/:path*' },
// ------------------------------------^
];
Run Code Online (Sandbox Code Playgroud)