Skip to content

ENG-8961: Single port is only prod option#6297

Merged
adhami3310 merged 18 commits intomainfrom
single-port-is-only-prod-option
Apr 9, 2026
Merged

ENG-8961: Single port is only prod option#6297
adhami3310 merged 18 commits intomainfrom
single-port-is-only-prod-option

Conversation

@adhami3310
Copy link
Copy Markdown
Member

No description provided.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 7, 2026

Merging this PR will not alter performance

✅ 9 untouched benchmarks


Comparing single-port-is-only-prod-option (12da11b) with main (08ee62a)

Open in CodSpeed

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 7, 2026

Greptile Summary

This PR enforces single-port as the only production option, removing the ability to run the frontend and backend on separate ports in --env prod. The backend now mounts compiled frontend static files directly (via REFLEX_MOUNT_FRONTEND_COMPILED_APP) so both are served from one port, and run_granian_backend_prod switches from a subprocess to the direct Granian Python API.

  • The --single-port CLI flag is kept for backward compatibility but no longer changes behavior — production now always uses a single port regardless of whether the flag is passed.

Confidence Score: 5/5

This PR is safe to merge — the prod single-port enforcement is logically consistent and all previously flagged P1 issues have been resolved.

All prior P0/P1 findings (always-truthy enum guard, loglevel silently dropped in Granian prod, ProcessPoolExecutor leak) are resolved in the current code. The only remaining finding is a P2 UX note that --single-port is now a no-op and could benefit from a deprecation warning. No correctness or reliability issues remain.

reflex/reflex.py — the --single-port flag validation block is now redundant and could mislead users or deploy scripts that relied on the flag to opt into single-port mode.

Vulnerabilities

No security concerns identified. The static file serving via Starlette StaticFiles is standard, and the Granian direct-API switch does not introduce new attack surface.

Important Files Changed

Filename Overview
reflex/reflex.py Adds --single-port flag (now redundant with prod always using single port) and updates _run/_run_prod to enforce single-port in production; guard logic and enum comparisons are correct.
reflex/utils/exec.py Adds run_frontend_prod and _frontend_prod_app for frontend-only prod serving; run_granian_backend_prod switches to direct Granian API and correctly passes loglevel.value as the env-var default.
scripts/integration.sh Prod mode now only waits for one port (3000) instead of two (3000 and 8000), consistent with single-port production.
reflex/app.py Mounts compiled frontend static files in the backend ASGI app when REFLEX_MOUNT_FRONTEND_COMPILED_APP is set, enabling single-port fullstack prod serving.
tests/units/test_prerequisites.py Adds test for PackageJson.Commands.get_prod_command with various frontend_path values; looks correct.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[reflex run] --> B{env?}
    B -- dev --> C[_run_dev]
    B -- prod --> D{ports conflict?}
    D -- yes --> E[SystemExit: must use same port]
    D -- no --> F[resolve single port]
    F --> G[_run_prod]
    G --> H[config: frontend_port = backend_port = port]
    H --> I{running_mode?}
    I -- has_backend --> J[run_backend_prod\nmount_frontend_compiled_app=has_frontend]
    I -- frontend only --> K[run_frontend_prod]
    J --> L{granian?}
    L -- yes --> M[run_granian_backend_prod\nGranian direct API]
    L -- no --> N[run_uvicorn_backend_prod]
    K --> L
    C --> O[run_frontend dev port]
    C --> P[run_backend dev port]
Loading

Reviews (3): Last reviewed commit: "fix autosetters" | Re-trigger Greptile

@adhami3310 adhami3310 changed the title Single port is only prod option ENG-8961: Single port is only prod option Apr 7, 2026
@linear
Copy link
Copy Markdown

linear bot commented Apr 7, 2026

@masenf
Copy link
Copy Markdown
Collaborator

masenf commented Apr 7, 2026

@greptile-apps re-review this PR

@masenf
Copy link
Copy Markdown
Collaborator

masenf commented Apr 9, 2026

@greptile-apps re-review this PR

masenf
masenf previously approved these changes Apr 9, 2026
Copy link
Copy Markdown
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

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

ship it, with optional/follow-on feedback

@adhami3310 adhami3310 merged commit 1dd2d1a into main Apr 9, 2026
40 checks passed
@adhami3310 adhami3310 deleted the single-port-is-only-prod-option branch April 9, 2026 17:24
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.

2 participants