Run a component with a development server
(
component: RootComponentConstructor,
host: str = "127.0.0.1",
port: int | None = None,
implementation: BackendType[Any] | None = None,
)
| 24 | |
| 25 | |
| 26 | def run( |
| 27 | component: RootComponentConstructor, |
| 28 | host: str = "127.0.0.1", |
| 29 | port: int | None = None, |
| 30 | implementation: BackendType[Any] | None = None, |
| 31 | ) -> None: |
| 32 | """Run a component with a development server""" |
| 33 | logger.warning(_DEVELOPMENT_RUN_FUNC_WARNING) |
| 34 | |
| 35 | implementation = implementation or import_module("reactpy.backend.default") |
| 36 | app = implementation.create_development_app() |
| 37 | implementation.configure(app, component) |
| 38 | port = port or find_available_port(host) |
| 39 | app_cls = type(app) |
| 40 | |
| 41 | logger.info( |
| 42 | "ReactPy is running with '%s.%s' at http://%s:%s", |
| 43 | app_cls.__module__, |
| 44 | app_cls.__name__, |
| 45 | host, |
| 46 | port, |
| 47 | ) |
| 48 | asyncio.run(implementation.serve_development_app(app, host, port)) |
| 49 | |
| 50 | |
| 51 | def find_available_port(host: str, port_min: int = 8000, port_max: int = 9000) -> int: |
no test coverage detected