javascript - NextJS 在生产中重写
问题描述
我在开发中发现了对代理到我的后端服务器的重写:
https://nextjs.org/docs/api-reference/next.config.js/rewrites
rewrites: async () => [
...nextI18NextRewrites(localeSubpaths),
{ source: '/api/:path*', destination: 'http://localhost:8080/:path*' },
],
如果 url 不是本地主机,这在生产中如何工作?
对于目的地,我需要添加完整域还是需要单独的开发/生产重写规则?
解决方案
只需从目标中删除域部分并使用absolute
路径。
rewrites: async () => [
...nextI18NextRewrites(localeSubpaths),
{ source: '/api/:path*', destination: '/:path*' },
// ------------------------------------^
];
推荐阅读
- animation - 转换框的问题:填充框和火狐
- symfony4 - 如何将 Date JsonObject 转换为字符串?
- bash - 传递用逗号分隔的bash数组
- networking - 如何找到较低层使用的协议?
- r - plotly 和 ggplot 图例顺序交互
- python - AWS ECR ListImages 结果有一个奇怪的顺序
- android - 当 EditText 具有边框背景和 maxLines 属性时,它的高度会略有变化
- google-app-engine - 如何从 Google App Engine(Python 3)写入 Google Cloud Storage 中的文件
- magento - 在 Magento 2 的销售订单网格中正确添加新列
- r - 计算总经过时间