serverActions
用于在 Next.js 应用中配置服务器操作行为的选项。
¥Options for configuring Server Actions behavior in your Next.js application.
allowedOrigins
可以从中调用服务器操作的额外安全源域的列表。Next.js 将服务器操作请求的来源与主机域进行比较,确保它们匹配以防止 CSRF 攻击。如果未提供,则仅允许相同来源。
¥A list of extra safe origin domains from which Server Actions can be invoked. Next.js compares the origin of a Server Action request with the host domain, ensuring they match to prevent CSRF attacks. If not provided, only the same origin is allowed.
bodySizeLimit
默认情况下,发送给 Server Action 的请求体的最大大小为 1MB,以防止解析大量数据时消耗过多的服务器资源,以及潜在的 DDoS 攻击。
¥By default, the maximum size of the request body sent to a Server Action is 1MB, to prevent the consumption of excessive server resources in parsing large amounts of data, as well as potential DDoS attacks.
但是,你可以使用 serverActions.bodySizeLimit
选项配置此限制。它可以采用字节数或字节支持的任何字符串格式,例如 1000
、'500kb'
或 '3mb'
。
¥However, you can configure this limit using the serverActions.bodySizeLimit
option. It can take the number of bytes or any string format supported by bytes, for example 1000
, '500kb'
or '3mb'
.
启用服务器操作 (v13)
¥Enabling Server Actions (v13)
服务器操作成为 Next.js 14 中的一项稳定功能,并且默认启用。但是,如果你使用的是早期版本的 Next.js,则可以通过将 experimental.serverActions
设置为 true
来启用它们。
¥Server Actions became a stable feature in Next.js 14, and are enabled by default. However, if you are using an earlier version of Next.js, you can enable them by setting experimental.serverActions
to true
.