Skip to content

single port prod#5839

Merged
adhami3310 merged 3 commits intomainfrom
single-port-prod
Oct 2, 2025
Merged

single port prod#5839
adhami3310 merged 3 commits intomainfrom
single-port-prod

Conversation

@adhami3310
Copy link
Member

No description provided.

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.

Greptile Overview

Summary

This PR implements a single-port production deployment mode for Reflex applications. The change allows both the frontend and backend to run on the same port in production, which simplifies deployment architectures and is particularly beneficial for containerized environments and cloud platforms.

The implementation works by introducing a new --single-port CLI flag that restricts usage to production mode only. When enabled, instead of running separate frontend and backend processes on different ports, the backend server mounts the compiled frontend static files directly using FastAPI's StaticFiles feature. This is controlled by a new internal environment variable REFLEX_MOUNT_FRONTEND_COMPILED_APP.

Key architectural changes include:

  • CLI validation logic that prevents single-port mode in development (where separate ports enable hot reloading)
  • Auto-detection when frontend and backend ports are explicitly set to the same value
  • Backend server modification to serve static frontend assets when the environment variable is set
  • Refactored console output functions for better code organization
  • Port handling logic that ensures proper configuration in single-port mode

This fits well with Reflex's deployment flexibility goals and follows common web framework patterns where the backend serves pre-compiled frontend assets in production environments.

Changed Files
Filename Score Overview
reflex/reflex.py 4/5 Adds single-port CLI flag with validation logic and execution flow changes
reflex/environment.py 5/5 Adds internal environment variable to control frontend mounting behavior
reflex/utils/exec.py 4/5 Implements backend mounting functionality and refactors console output
reflex/app.py 4/5 Mounts compiled frontend static files when environment variable is enabled

Confidence score: 4/5

  • This PR is safe to merge with moderate risk due to well-structured implementation of a valuable feature
  • Score reflects solid architecture and validation logic, but complex deployment functionality needs thorough testing
  • Pay close attention to reflex/app.py for proper static file mounting and reflex/reflex.py for CLI validation logic

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI
    participant Config
    participant App
    participant Environment
    participant Backend
    participant Frontend

    User->>CLI: "reflex run --single-port --env=PROD"
    CLI->>CLI: "Validate single-port constraints"
    CLI->>Config: "Get current config"
    CLI->>CLI: "Set backend_port = frontend_port"
    CLI->>Environment: "Set environment variables"
    Environment->>Environment: "REFLEX_MOUNT_FRONTEND_COMPILED_APP = True"
    CLI->>App: "_run(single_port=True)"
    App->>App: "setup_frontend_prod()"
    App->>Backend: "run_backend_prod(mount_frontend_compiled_app=True)"
    Backend->>Backend: "Mount compiled frontend at '/'"
    Backend->>User: "Serve both frontend and backend on same port"
Loading

4 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 1, 2025

CodSpeed Performance Report

Merging #5839 will not alter performance

Comparing single-port-prod (c54fcd0) with main (5feefe3)

Summary

✅ 8 untouched

@adhami3310 adhami3310 merged commit 7331abc into main Oct 2, 2025
51 of 53 checks passed
@adhami3310 adhami3310 deleted the single-port-prod branch October 2, 2025 15:49
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