Skip to content

Commit 7023223

Browse files
committed
refactor: support bool | list[str] for vite_allowed_hosts
1 parent 5170c6f commit 7023223

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

reflex/compiler/templates.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ def vite_config_template(
502502
force_full_reload: bool,
503503
experimental_hmr: bool,
504504
sourcemap: bool | Literal["inline", "hidden"],
505-
allowed_hosts: bool = False,
505+
allowed_hosts: bool | list[str] = False,
506506
):
507507
"""Template for vite.config.js.
508508
@@ -512,12 +512,17 @@ def vite_config_template(
512512
force_full_reload: Whether to force a full reload on changes.
513513
experimental_hmr: Whether to enable experimental HMR features.
514514
sourcemap: The sourcemap configuration.
515-
allowed_hosts: Whether to allow all hosts in the Vite dev server.
515+
allowed_hosts: Allow all hosts (True), specific hosts (list of strings), or only localhost (False).
516516
517517
Returns:
518518
Rendered vite.config.js content as string.
519519
"""
520-
allowed_hosts_line = "\n allowedHosts: true," if allowed_hosts else ""
520+
if allowed_hosts is True:
521+
allowed_hosts_line = "\n allowedHosts: true,"
522+
elif isinstance(allowed_hosts, list) and allowed_hosts:
523+
allowed_hosts_line = f"\n allowedHosts: {json.dumps(allowed_hosts)},"
524+
else:
525+
allowed_hosts_line = ""
521526
return rf"""import {{ fileURLToPath, URL }} from "url";
522527
import {{ reactRouter }} from "@react-router/dev/vite";
523528
import {{ defineConfig }} from "vite";

reflex/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,10 @@ class BaseConfig:
213213
dataclasses.field(default=("*",))
214214
)
215215

216-
# Whether to allow all hosts in Vite dev server (prevents 403 errors in Docker, Codespaces, etc.).
217-
vite_allowed_hosts: bool = False
216+
# Allowed hosts for the Vite dev server. Set to True to allow all hosts,
217+
# or provide a list of hostnames (e.g. ["myservice.local"]) to allow specific ones.
218+
# Prevents 403 errors in Docker, Codespaces, reverse proxies, etc.
219+
vite_allowed_hosts: bool | list[str] = False
218220

219221
# Whether to use React strict mode.
220222
react_strict_mode: bool = True

0 commit comments

Comments
 (0)