Commit 05bce9de authored by Cursor Agent's avatar Cursor Agent

docs: add environment variable documentation for allowed origins

- Document NEXT_ALLOWED_DEV_ORIGINS for allowedDevOrigins
- Document NEXT_SERVER_ACTIONS_ALLOWED_ORIGINS for serverActions.allowedOrigins
- Explain that env vars are merged with config file values
- Add usage examples for both environment variables
parent 3c8b8668
...@@ -9,6 +9,8 @@ Next.js does not automatically block cross-origin requests during development, b ...@@ -9,6 +9,8 @@ Next.js does not automatically block cross-origin requests during development, b
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. 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.
## Configuration File
`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: `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 filename="next.config.js" ```js filename="next.config.js"
...@@ -16,3 +18,13 @@ module.exports = { ...@@ -16,3 +18,13 @@ module.exports = {
allowedDevOrigins: ['local-origin.dev', '*.local-origin.dev'], allowedDevOrigins: ['local-origin.dev', '*.local-origin.dev'],
} }
``` ```
## Environment Variable
You can also configure allowed dev origins using the `NEXT_ALLOWED_DEV_ORIGINS` environment variable. This is useful for sandboxed or containerized environments where you don't want to modify the user's configuration file:
```bash
NEXT_ALLOWED_DEV_ORIGINS="example.com,*.v0.dev" npm run dev
```
The environment variable accepts a comma-separated list of origins. Values from the environment variable are merged with any values specified in `next.config.js`, allowing both sources to work together.
...@@ -9,6 +9,8 @@ Options for configuring Server Actions behavior in your Next.js application. ...@@ -9,6 +9,8 @@ Options for configuring Server Actions behavior in your Next.js application.
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. 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.
### Configuration File
```js filename="next.config.js" ```js filename="next.config.js"
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
...@@ -21,6 +23,16 @@ module.exports = { ...@@ -21,6 +23,16 @@ module.exports = {
} }
``` ```
### Environment Variable
You can also configure allowed origins using the `NEXT_SERVER_ACTIONS_ALLOWED_ORIGINS` environment variable. This is useful for sandboxed or containerized environments where you don't want to modify the user's configuration file:
```bash
NEXT_SERVER_ACTIONS_ALLOWED_ORIGINS="my-proxy.com,*.my-proxy.com" npm run dev
```
The environment variable accepts a comma-separated list of origins. Values from the environment variable are merged with any values specified in `next.config.js`, allowing both sources to work together.
## `bodySizeLimit` ## `bodySizeLimit`
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. 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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment