Skip to content

feat: add vite_allowed_hosts config option for Vite dev server#6147

Open
milochen0418 wants to merge 1 commit intoreflex-dev:mainfrom
milochen0418:feat/vite-allowed-hosts-config
Open

feat: add vite_allowed_hosts config option for Vite dev server#6147
milochen0418 wants to merge 1 commit intoreflex-dev:mainfrom
milochen0418:feat/vite-allowed-hosts-config

Conversation

@milochen0418
Copy link
Contributor

Add a configurable vite_allowed_hosts field to rx.Config that controls whether allowedHosts: true is set in the Vite dev server configuration.

This allows users running Reflex in Docker, Codespaces, or behind a reverse proxy to opt-in to allowing all hosts, preventing 403 Forbidden errors from Vite's host header validation.

Default is False (original behavior, Vite only allows localhost). Users can enable it in rxconfig.py:
config = rx.Config(app_name="myapp", vite_allowed_hosts=True)
Or via environment variable:
REFLEX_VITE_ALLOWED_HOSTS=true reflex run

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

New Feature Submission:

  • Does your submission pass the tests?
  • Have you linted your code locally prior to submission?

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

After these steps, you're ready to open a pull request.

a. Give a descriptive title to your PR.

b. Describe your changes.

c. Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes (if such).

Add a configurable `vite_allowed_hosts` field to `rx.Config` that controls
whether `allowedHosts: true` is set in the Vite dev server configuration.

This allows users running Reflex in Docker, Codespaces, or behind a reverse
proxy to opt-in to allowing all hosts, preventing 403 Forbidden errors from
Vite's host header validation.

Default is `False` (original behavior, Vite only allows localhost).
Users can enable it in rxconfig.py:
  config = rx.Config(app_name="myapp", vite_allowed_hosts=True)
Or via environment variable:
  REFLEX_VITE_ALLOWED_HOSTS=true reflex run
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 28, 2026

Merging this PR will degrade performance by 3.03%

❌ 1 regressed benchmark
✅ 7 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
test_compile_stateful[_stateful_page] 150.8 µs 155.5 µs -3.03%

Comparing milochen0418:feat/vite-allowed-hosts-config (5170c6f) with main (e7c3742)

Open in CodSpeed

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 28, 2026

Greptile Summary

This PR adds a new vite_allowed_hosts configuration option to allow users to opt-in to permitting all hosts in the Vite dev server, addressing 403 errors in containerized environments (Docker, Codespaces, reverse proxies).

Key changes:

  • Added vite_allowed_hosts: bool field to rx.Config (defaults to False for backward compatibility)
  • Modified vite config template to conditionally insert allowedHosts: true in server configuration
  • Environment variable support via REFLEX_VITE_ALLOWED_HOSTS works automatically through existing config loading

Implementation quality:
The code follows existing patterns and is well-structured with proper documentation. However, there's a concern about whether allowedHosts is a valid Vite configuration option - Vite's official documentation doesn't list this server option (it's a webpack-dev-server feature). Consider verifying this works with the version of Vite being used.

Confidence Score: 3/5

  • This PR is safe to merge with verification needed for the Vite configuration option
  • The implementation is clean and follows existing patterns, but there's uncertainty about whether allowedHosts is a supported Vite server option. This needs verification to ensure the feature actually works as intended. No tests were added for this new configuration.
  • reflex/compiler/templates.py needs verification that allowedHosts works with Vite

Important Files Changed

Filename Overview
reflex/compiler/templates.py Added allowed_hosts parameter to vite_config_template with conditional insertion of allowedHosts config
reflex/config.py Added vite_allowed_hosts boolean field to BaseConfig with proper documentation
reflex/utils/frontend_skeleton.py Passes config.vite_allowed_hosts to vite_config_template function

Last reviewed commit: 5170c6f

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@milochen0418
Copy link
Contributor Author

Merging this PR will degrade performance by 3.03%

❌ 1 regressed benchmark ✅ 7 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
test_compile_stateful[_stateful_page] 150.8 µs 155.5 µs -3.03%
Comparing milochen0418:feat/vite-allowed-hosts-config (5170c6f) with main (e7c3742)

Open in CodSpeed

The 3.03% regression in test_compile_stateful (5µs difference) is within measurement noise and unrelated to this change — we only added a default False parameter and a conditional string line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant