Skip to main content

服务器代理配置分组在 server.proxy 对象下

¥Server proxy configurations are grouped under the server.proxy object

在 Strapi 5 中,所有代理配置选项现在都通过 /config/server.js|ts 中的 server.proxy 对象进行配置,无论它们是针对 strapi.fetch 内发出的请求,还是针对 koa  服务器的全局代理代理。

¥In Strapi 5, all proxy configuration options are now configured through the server.proxy object in /config/server.js|ts, whether they are for requests made within strapi.fetch or for the global proxy agent for the koa  server.

此页面是 重大变更数据库 的一部分,提供有关重大更改的信息以及从 Strapi v4 迁移到 Strapi 5 的其他说明。

¥This page is part of the breaking changes database and provides information about the breaking change and additional instructions to migrate from Strapi v4 to Strapi 5.

 Is this breaking change affecting plugins?No
 Is this breaking change automatically handled by a codemod?No

重大更改描述

¥Breaking change description

在 Strapi v4 中

¥In Strapi v4

  • server.globalProxy 用于通过 strapi.fetch 配置所有请求。

    ¥server.globalProxy is used to configure all requests through strapi.fetch.

  • server.proxy 用于设置 koa 服务器的 proxy 选项的值。

    ¥server.proxy is used to set the value of koa server’s proxy option.

在 Strapi 5 中

¥In Strapi 5

所有配置选项都分组在 server.proxy 对象下。

¥All configuration options are grouped under the server.proxy object.

迁移

¥Migration

本节重新组合了有关引入的重大更改的有用说明和程序。

¥This section regroups useful notes and procedures about the introduced breaking change.

注意

¥Notes

有关 server.proxy 配置在 Strapi 5 中的工作原理的更多信息,请参阅 服务器配置 文档。

¥Additional information about how the server.proxy configuration works in Strapi 5 is available in the server configuration documentation.

手动迁移

¥Manual migration

用户需要手动更新代码:

¥Users will need to manually update the code:

  • 如果使用 server.proxy,则需要移至 server.proxy.koa

    ¥If server.proxy is used, it needs to move to server.proxy.koa.

  • 如果使用 server.globalProxy,你有 2 个选择:

    ¥If server.globalProxy is used, you have 2 choices:

    • 将其移动到 server.proxy.global,并注意它现在除了 strapi.fetch 请求之外还适用于 HTTP/HTTPS 请求,

      ¥move it to server.proxy.global and be aware that it will now work for HTTP/HTTPS requests in addition to strapi.fetch requests,

    • 或将其移动到 server.proxy.fetch 以保持与 Strapi v4 中完全相同的功能,其中只有获取是代理的。

      ¥or move it to server.proxy.fetch to keep the exact same functionality as in Strapi v4, where only fetch was proxied.