Skip to content

allowedDevOrigins

Next.js 在开发过程中不会自动阻止跨域请求,但会在 Next.js 未来的主要版本中默认阻止,以防止未经授权请求开发模式下可用的内部资源/端点。

¥Next.js does not automatically block cross-origin requests during development, but will block by default in a future major version of Next.js to prevent unauthorized requesting of internal assets/endpoints that are available in development mode.

要将 Next.js 应用配置为允许来自服务器初始化时使用的主机名(默认为 localhost)以外的来源的请求,你可以使用 allowedDevOrigins 配置选项。

¥To configure a Next.js application to allow requests from origins other than the hostname the server was initialized with (localhost by default) you can use the allowedDevOrigins config option.

allowedDevOrigins 允许你设置可在开发模式下使用的其他来源。例如,要使用 local-origin.dev 而不是仅使用 localhost,请打开 next.config.js 并添加 allowedDevOrigins 配置:

¥allowedDevOrigins allows you to set additional origins that can be used in development mode. For example, to use local-origin.dev instead of only localhost, open next.config.js and add the allowedDevOrigins config:

js
module.exports = {
  allowedDevOrigins: ['local-origin.dev', '*.local-origin.dev'],
}

Next.js v15.3 中文网 - 粤ICP备13048890号