在 Next.js 应用中配置 Server Actions 行为的选项。
allowedOrigins一个额外的安全来源域列表,Server Actions 可以从这些域被调用。Next.js 会将 Server Action 请求的来源与主机域进行比较,确保它们匹配以防止 CSRF 攻击。如果未提供此选项,则只允许同源请求。
/** @type {import('next').NextConfig} */
module.exports = {
experimental: {
serverActions: {
allowedOrigins: ['my-proxy.com', '*.my-proxy.com'],
},
},
}bodySizeLimit默认情况下,发送到 Server Action 的请求体最大大小为 1MB,以防止服务器在解析大量数据时消耗过多资源,以及潜在的 DDoS 攻击。
然而,你可以使用 serverActions.bodySizeLimit 选项来配置此限制。它可以是一个字节数,或者任何支持字节的字符串格式,例如 1000、'500kb' 或 '3mb'。
/** @type {import('next').NextConfig} */
module.exports = {
experimental: {
serverActions: {
bodySizeLimit: '2mb',
},
},
}Server Actions 在 Next.js 14 中成为了一个稳定功能,并且默认启用。然而,如果你使用的是早期版本的 Next.js,你可以通过将 experimental.serverActions 设置为 true 来启用它们。
/** @type {import('next').NextConfig} */
const config = {
experimental: {
serverActions: true,
},
}
module.exports = config