MCPcopy
hub / github.com/reflex-dev/reflex / _run

Function _run

reflex/reflex.py:262–376  ·  view source on GitHub ↗

Run the app in the given directory.

(
    *,
    env: constants.Env = constants.Env.DEV,
    running_mode: constants.RunningMode = constants.RunningMode.FULLSTACK,
    frontend_port: int | None = None,
    backend_port: int | None = None,
    backend_host: str | None = None,
)

Source from the content-addressed store, hash-verified

260
261
262def _run(
263 *,
264 env: constants.Env = constants.Env.DEV,
265 running_mode: constants.RunningMode = constants.RunningMode.FULLSTACK,
266 frontend_port: int | None = None,
267 backend_port: int | None = None,
268 backend_host: str | None = None,
269):
270 """Run the app in the given directory."""
271 from reflex.istate.manager import reset_disk_state_manager
272 from reflex.utils import exec, prerequisites, processes
273
274 if frontend_port and not running_mode.has_frontend():
275 console.error("Cannot specify --frontend-port when not running frontend.")
276 raise SystemExit(1)
277 if backend_port and not running_mode.has_backend():
278 console.error("Cannot specify --backend-port when not running backend.")
279 raise SystemExit(1)
280 if (
281 env == constants.Env.PROD
282 and frontend_port
283 and backend_port
284 and frontend_port != backend_port
285 ):
286 console.error("In production, frontend and backend must run on the same port.")
287 raise SystemExit(1)
288
289 config = get_config()
290
291 backend_host = backend_host or config.backend_host
292
293 # Set env mode in the environment
294 environment.REFLEX_ENV_MODE.set(env)
295
296 # Show system info
297 exec.output_system_info()
298
299 if running_mode == constants.RunningMode.BACKEND_ONLY:
300 _skip_compile()
301
302 prerequisites.assert_in_reflex_dir()
303
304 # Check that the app is initialized.
305 if running_mode.has_frontend() and prerequisites.needs_reinit():
306 _init(name=config.app_name)
307
308 # Delete the states folder if it exists.
309 reset_disk_state_manager()
310
311 # Apply the new ports and host to the config.
312 if frontend_port != config.frontend_port:
313 config._set_persistent(frontend_port=frontend_port)
314 if backend_port != config.backend_port:
315 config._set_persistent(backend_port=backend_port)
316 if backend_host != config.backend_host:
317 config._set_persistent(backend_host=backend_host)
318
319 # Reload the config to make sure the env vars are persistent.

Callers 1

runFunction · 0.70

Calls 11

get_configFunction · 0.90
reset_disk_state_managerFunction · 0.90
_skip_compileFunction · 0.85
_initFunction · 0.85
_run_devFunction · 0.85
_run_prodFunction · 0.85
has_frontendMethod · 0.80
has_backendMethod · 0.80
_set_persistentMethod · 0.80
lowerMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected