allowedDevOrigins
Lists extra origins allowed to request the development server's assets and endpoints.
allowedDevOrigins?: string[]Parameters
| Parameter | Type | Description |
|---|---|---|
$allowedDevOriginsoptional | string[]= only the hostname the server was initialized with (localhost) | Additional origins permitted to request the dev server in development mode. Entries are hostnames and may use a `*` wildcard for subdomains, for example `'*.local-origin.dev'`. |
By default the development server only answers requests for dev-only assets and endpoints that come from the hostname it was initialized with — normally localhost. Everything else is blocked, so a stranger on your network cannot pull source maps or hit internal dev routes. allowedDevOrigins adds hostnames to that allowlist.
When to reach for it
Any time the browser is not on localhost. Testing on a phone via your machine's LAN address, exposing the dev server through a tunnel such as ngrok or Cloudflare Tunnel, running behind a local reverse proxy on a custom .dev hostname, or opening the app from inside a container or VM that reaches the host by IP.
What trips people up
- The symptom is confusing. The page itself may load while HMR silently stops working or dev assets 404, because it is the dev-only requests that get blocked.
- Entries are hostnames, not full URLs — no scheme, no path.
- A tunnel that mints a new subdomain per session needs the wildcard form, otherwise you edit the config every restart.
- This is development only. It has no effect on
next buildornext start, so it is not a substitute for CORS headers in production.
Example
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
allowedDevOrigins: ['local-origin.dev', '*.local-origin.dev'],
}
export default nextConfigWhen to use it
- Open the dev server from a phone on the same Wi-Fi using your machine's LAN IP.
- Share work in progress through an ngrok or Cloudflare tunnel.
- Serve development behind a local reverse proxy on a custom hostname such as app.local-origin.dev.
- Reach the host dev server from a browser running inside a container or VM.
Frequently asked questions
How do I fix "Blocked cross-origin request" in next dev?
Add the origin's hostname to `allowedDevOrigins` in next.config.ts and restart the dev server. The dev server only trusts the hostname it started on (localhost by default) and blocks other origins from requesting dev-only assets and endpoints, which is why the error appears as soon as you browse via a LAN IP or a tunnel URL.
Can I use a wildcard in allowedDevOrigins?
Yes — the documented form is a leading wildcard on the subdomain, such as '*.local-origin.dev'. That is what you want for tunnel providers that generate a new subdomain per session. Entries are hostnames only, without a scheme or port.
Does allowedDevOrigins affect production?
No. It applies to the development server only and has no bearing on `next build` or `next start`. For cross-origin control in production, set CORS response headers instead.
More examples
Allowing a LAN address for device testing
With this in place, `next dev` accepts dev requests arriving at http://192.168.1.42:3000 from a phone or tablet on the same network. Note the entry is the bare host — no http:// prefix and no port. Without it the HTML may still render while hot reload and other dev-only endpoints are rejected, which reads like a broken dev server rather than a blocked origin.
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
allowedDevOrigins: ['192.168.1.42'],
}
export default nextConfigWildcard subdomains for a tunnel
Tunnels hand out a fresh subdomain on most restarts, so listing an exact host means editing the config every session. The `*.` form covers the whole provider domain once. Keep the wildcard as narrow as the provider allows — this list decides who may pull dev assets from your machine while the tunnel is open.
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
allowedDevOrigins: ['*.ngrok-free.app', '*.trycloudflare.com'],
}
export default nextConfigOnly widening the allowlist in development
The option is already ignored outside development, so this is about the config file rather than the server: it keeps hostnames from a teammate's network out of production config review and makes the intent explicit. Since Next.js 16, checking process.argv for 'dev' does not work for this — `next dev` no longer loads the config in the CLI process — so branch on NODE_ENV or use the phase argument.
import type { NextConfig } from 'next'
const devOrigins =
process.env.NODE_ENV === 'development'
? ['*.local-origin.dev', '192.168.1.42']
: []
const nextConfig: NextConfig = {
allowedDevOrigins: devOrigins,
}
export default nextConfig
Discussion