reflex-dev / reflex

🕸️ Web apps in pure Python 🐍
https://reflex.dev
Apache License 2.0
20.46k stars 1.18k forks source link

[IMPL] - Custom backend server and improved configuration capabilities #4337

Open KronosDev-Pro opened 2 weeks ago

KronosDev-Pro commented 2 weeks ago

Idea

Customize the backend server configuration as you like, and create a complete new backend server support.

can be easily split into another reflex package, for example pip install reflex[granian].

Example

We can define which BackendServer to use for development and production modes and thus customize the configuration (all parameters for each BackendServer are the actual parameters corresponding to the web server involved).

import reflex as rx
from reflex import server

config = rx.Config(
    app_name="examples",
    backend_server_dev = server.GunicornBackendServer(
        worker_class="uvicorn.workers.UvicornH11Worker",
        max_requests=100,
        max_requests_jitter=25,
        timeout=120,
        threads=1,
        workers=1,
    ),
    backend_server_prod = server.GranianBackendServer(
        threads=2,
        workers=4,
    )
)

We can also create a customized BackendServer with the CustomBackendServer class, such as GranianBackendServer


All Submissions:

Type of change

New Feature Submission:

Changes To Core Features:

mmmcorpsvit commented 2 weeks ago

hm... why not just use Pydantic Config package?

KronosDev-Pro commented 2 weeks ago

hm... why not just use Pydantic Config package?

Basically, dataclasses is a native package that brings simplicity, performance and more customization possibilities. What's more, for this type of configuration, it doesn't need the validation and serialization/deserialization provided by pydantic.