MCPcopy Create free account
hub / github.com/pywebio/PyWebIO / webio_routes

Function webio_routes

pywebio/platform/fastapi.py:113–145  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

111
112
113def 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
148def start_server(applications, port=0, host='', cdn=True, reconnect_timeout=0,

Callers 1

asgi_appFunction · 0.85

Calls 6

strip_spaceFunction · 0.85
make_applicationsFunction · 0.85
cdn_validationFunction · 0.85
_webio_routesFunction · 0.85
is_same_siteMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…