【问题标题】:NextJS rewrites in productionNextJS 在生产中重写
【发布时间】:2021-01-28 12:07:03
【问题描述】:

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

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

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

如果 url 不是 localhost,这在生产中如何工作?

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

【问题讨论】:

    标签: javascript proxy url-rewriting next.js


    【解决方案1】:

    只需从目标中删除域部分并使用absolute 路径。

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

    【讨论】:

      猜你喜欢
      • 2021-11-03
      • 2020-10-04
      • 2020-10-19
      • 2022-11-01
      • 2021-07-02
      • 1970-01-01
      • 2020-10-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多