Get the FastAPI/Starlette routes for running PyWebIO applications. The API communicates with the browser using WebSocket protocol. The arguments of ``webio_routes()`` have the same meaning as for :func:`pywebio.platform.fastapi.start_server` .. versionadded:: 1.3 :return: FastAPI
(applications, cdn=True, reconnect_timeout=0, allowed_origins=None, check_origin=None)
| 111 | |
| 112 | |
| 113 | def webio_routes(applications, cdn=True, reconnect_timeout=0, allowed_origins=None, check_origin=None): |
| 114 | """Get the FastAPI/Starlette routes for running PyWebIO applications. |
| 115 | |
| 116 | The API communicates with the browser using WebSocket protocol. |
| 117 | |
| 118 | The arguments of ``webio_routes()`` have the same meaning as for :func:`pywebio.platform.fastapi.start_server` |
| 119 | |
| 120 | .. versionadded:: 1.3 |
| 121 | |
| 122 | :return: FastAPI/Starlette routes |
| 123 | """ |
| 124 | try: |
| 125 | import websockets |
| 126 | except Exception: |
| 127 | raise RuntimeError(strip_space(""" |
| 128 | Missing dependency package `websockets` for websocket support. |
| 129 | You can install it with the following command: |
| 130 | pip install websockets |
| 131 | """.strip(), n=8)) from None |
| 132 | |
| 133 | applications = make_applications(applications) |
| 134 | for target in applications.values(): |
| 135 | register_session_implement_for_target(target) |
| 136 | |
| 137 | cdn = cdn_validation(cdn, 'error') |
| 138 | |
| 139 | if check_origin is None: |
| 140 | check_origin_func = partial(OriginChecker.check_origin, allowed_origins=allowed_origins or []) |
| 141 | else: |
| 142 | check_origin_func = lambda origin, host: OriginChecker.is_same_site(origin, host) or check_origin(origin) |
| 143 | |
| 144 | return _webio_routes(applications=applications, cdn=cdn, check_origin_func=check_origin_func, |
| 145 | reconnect_timeout=reconnect_timeout) |
| 146 | |
| 147 | |
| 148 | def start_server(applications, port=0, host='', cdn=True, reconnect_timeout=0, |
no test coverage detected
searching dependent graphs…