Skip to content

Commit 38ff389

Browse files
committed
add polling transport option
1 parent 579e922 commit 38ff389

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

reflex/.templates/web/utils/state.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ export const useEventLoop = (
854854
await connect(
855855
socket,
856856
dispatch,
857-
["websocket"],
857+
[env.TRANSPORT],
858858
setConnectErrors,
859859
client_storage,
860860
navigate,

reflex/app.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -531,20 +531,17 @@ def _setup_state(self) -> None:
531531
if not self.sio:
532532
self.sio = AsyncServer(
533533
async_mode="asgi",
534-
cors_allowed_origins=(
535-
"*"
536-
if config.cors_allowed_origins == ("*",)
537-
else list(config.cors_allowed_origins)
538-
),
539-
cors_credentials=True,
534+
cors_allowed_origins=[],
535+
cors_credentials=False,
540536
max_http_buffer_size=environment.REFLEX_SOCKET_MAX_HTTP_BUFFER_SIZE.get(),
541537
ping_interval=environment.REFLEX_SOCKET_INTERVAL.get(),
542538
ping_timeout=environment.REFLEX_SOCKET_TIMEOUT.get(),
543539
json=SimpleNamespace(
544540
dumps=staticmethod(format.json_dumps),
545541
loads=staticmethod(json.loads),
546542
),
547-
transports=["websocket"],
543+
allow_upgrades=False,
544+
transports=[config.transport],
548545
)
549546
elif getattr(self.sio, "async_mode", "") != "asgi":
550547
msg = f"Custom `sio` must use `async_mode='asgi'`, not '{self.sio.async_mode}'."

reflex/config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from importlib.util import find_spec
1111
from pathlib import Path
1212
from types import ModuleType
13-
from typing import TYPE_CHECKING, Any, ClassVar
13+
from typing import TYPE_CHECKING, Any, ClassVar, Literal
1414

1515
from reflex import constants
1616
from reflex.constants.base import LogLevel
@@ -254,6 +254,9 @@ class BaseConfig:
254254
# List of fully qualified import paths of plugins to disable in the app (e.g. reflex.plugins.sitemap.SitemapPlugin).
255255
disable_plugins: list[str] = dataclasses.field(default_factory=list)
256256

257+
# The transport method for client-server communication.
258+
transport: Literal["websocket", "polling"] = "websocket"
259+
257260
# Whether to skip plugin checks.
258261
_skip_plugins_checks: bool = dataclasses.field(default=False, repr=False)
259262

reflex/utils/build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def set_env_json():
2020
str(prerequisites.get_web_dir() / constants.Dirs.ENV_JSON),
2121
{
2222
**{endpoint.name: endpoint.get_url() for endpoint in constants.Endpoint},
23+
"TRANSPORT": get_config().transport,
2324
"TEST_MODE": is_in_app_harness(),
2425
},
2526
)

0 commit comments

Comments
 (0)