serverActions
Next.js アプリケーションの Server Actions の動作を構成するためのオプション。
allowedOrigins
Server Actions を呼び出すことができる、追加の安全なオリジン ドメインのリスト。Next.js は、CSRF 攻撃を防ぐために、Server Action リクエストのオリジンとホスト ドメインを比較し、一致することを確認します。提供されない場合、同じオリジンのみが許可されます。
next.config.js
/** @type {import('next').NextConfig} */
module.exports = {
experimental: {
serverActions: {
allowedOrigins: ['my-proxy.com', '*.my-proxy.com'],
},
},
}bodySizeLimit
デフォルトでは、Server Actions に送信されるリクエストボディの最大サイズは 1MB です。これは、大量のデータを解析する際の過剰なサーバー リソースの消費や、潜在的な DDoS 攻撃を防ぐためです。
ただし、この制限は serverActions.bodySizeLimit オプションを使用して構成できます。バイト数または bytes でサポートされる任意の文字列形式を指定できます。たとえば、1000、'500kb'、または '3mb' などです。
next.config.js
/** @type {import('next').NextConfig} */
module.exports = {
experimental: {
serverActions: {
bodySizeLimit: '2mb',
},
},
}Server Actions の有効化 (v13)
Server Actions は Next.js 14 で安定版機能となり、デフォルトで有効になっています。ただし、それより前のバージョンの Next.js を使用している場合は、experimental.serverActions を true に設定することで有効にできます。
next.config.js
/** @type {import('next').NextConfig} */
const config = {
experimental: {
serverActions: true,
},
}
module.exports = config役に立ちましたか?