Skip to content

Commit 427d7c5

Browse files
authored
Revert "[ENG-4005] Proxy backend requests on '/' to the frontend (#3300)" (#4614)
This reverts commit 438b31f.
1 parent fe9c020 commit 427d7c5

File tree

12 files changed

+15
-782
lines changed

12 files changed

+15
-782
lines changed

.github/workflows/integration_tests.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ jobs:
8484
run: |
8585
poetry run reflex export --backend-only
8686
- name: Check run --backend-only before init for counter example
87-
env:
88-
WAIT_FOR_LISTENING_PORT_ARGS: --path ping
8987
run: |
9088
poetry run bash scripts/integration.sh ./reflex-examples/counter dev 8001 --backend-only --backend-port 8001
9189
- name: Init Website for counter example

.github/workflows/integration_tests_wsl.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ jobs:
7878
shell: wsl-bash {0}
7979
run: |
8080
export TELEMETRY_ENABLED=false
81-
export WAIT_FOR_LISTENING_PORT_ARGS="--path ping"
8281
dos2unix scripts/integration.sh
8382
poetry run bash scripts/integration.sh ./reflex-examples/counter dev 8001 --backend-only --backend-port 8001
8483
- name: Init Website for counter example

poetry.lock

Lines changed: 5 additions & 570 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ setuptools = ">=75.0"
4949
httpx = ">=0.25.1,<1.0"
5050
twine = ">=4.0.0,<7.0"
5151
tomlkit = ">=0.12.4,<1.0"
52-
asgiproxy = { version = "==0.1.1", optional = true }
5352
lazy_loader = ">=0.4"
5453
reflex-chakra = ">=0.6.0"
5554
typing_extensions = ">=4.6.0"
@@ -73,14 +72,10 @@ selenium = ">=4.11.0,<5.0"
7372
pytest-benchmark = ">=4.0.0,<6.0"
7473
playwright = ">=1.46.0"
7574
pytest-playwright = ">=0.5.1"
76-
asgiproxy = "==0.1.1"
7775

7876
[tool.poetry.scripts]
7977
reflex = "reflex.reflex:cli"
8078

81-
[tool.poetry.extras]
82-
proxy = ["asgiproxy"]
83-
8479
[build-system]
8580
requires = ["poetry-core>=1.5.1"]
8681
build-backend = "poetry.core.masonry.api"

reflex/app.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,6 @@ def __post_init__(self):
332332

333333
self.register_lifespan_task(windows_hot_reload_lifespan_hack)
334334

335-
# Enable proxying to frontend server.
336-
if not environment.REFLEX_BACKEND_ONLY.get():
337-
from reflex.proxy import proxy_middleware
338-
339-
self.register_lifespan_task(proxy_middleware)
340-
341335
def _enable_state(self) -> None:
342336
"""Enable state for the app."""
343337
if not self.state:

reflex/config.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
from typing_extensions import Annotated, get_type_hints
2828

29-
from reflex.utils.console import set_log_level
3029
from reflex.utils.exceptions import ConfigError, EnvironmentVarValueError
3130
from reflex.utils.types import GenericType, is_union, value_inside_optional
3231

@@ -600,7 +599,6 @@ class Config(Base):
600599
class Config:
601600
"""Pydantic config for the config."""
602601

603-
use_enum_values = False
604602
validate_assignment = True
605603

606604
# The name of the app (should match the name of the app directory).
@@ -720,9 +718,6 @@ def __init__(self, *args, **kwargs):
720718
self._non_default_attributes.update(kwargs)
721719
self._replace_defaults(**kwargs)
722720

723-
# Set the log level for this process
724-
set_log_level(self.loglevel)
725-
726721
if (
727722
self.state_manager_mode == constants.StateManagerMode.REDIS
728723
and not self.redis_url

reflex/proxy.py

Lines changed: 0 additions & 119 deletions
This file was deleted.

reflex/testing.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import reflex.utils.prerequisites
4545
import reflex.utils.processes
4646
from reflex.config import environment
47-
from reflex.proxy import proxy_middleware
4847
from reflex.state import (
4948
BaseState,
5049
StateManager,
@@ -299,9 +298,6 @@ def _initialize_app(self):
299298
self.state_manager = StateManagerRedis.create(self.app_instance.state)
300299
else:
301300
self.state_manager = self.app_instance._state_manager
302-
# Disable proxy for app harness tests.
303-
if proxy_middleware in self.app_instance.lifespan_tasks:
304-
self.app_instance.lifespan_tasks.remove(proxy_middleware)
305301

306302
def _reload_state_module(self):
307303
"""Reload the rx.State module to avoid conflict when reloading."""
@@ -369,12 +365,9 @@ async def _reset_backend_state_manager(self):
369365
def _start_frontend(self):
370366
# Set up the frontend.
371367
with chdir(self.app_path):
372-
backend_host, backend_port = self._poll_for_servers().getsockname()
373368
config = reflex.config.get_config()
374-
config.backend_port = backend_port
375369
config.api_url = "http://{0}:{1}".format(
376-
backend_host,
377-
backend_port,
370+
*self._poll_for_servers().getsockname(),
378371
)
379372
reflex.utils.build.setup_frontend(self.app_path)
380373

@@ -399,7 +392,6 @@ def _wait_frontend(self):
399392
self.frontend_url = m.group(1)
400393
config = reflex.config.get_config()
401394
config.deploy_url = self.frontend_url
402-
config.frontend_port = int(self.frontend_url.rpartition(":")[2])
403395
break
404396
if self.frontend_url is None:
405397
raise RuntimeError("Frontend did not start")
@@ -923,20 +915,17 @@ def _run_frontend(self):
923915
root=web_root,
924916
error_page_map=error_page_map,
925917
) as self.frontend_server:
926-
config = reflex.config.get_config()
927-
config.frontend_port = self.frontend_server.server_address[1]
928-
self.frontend_url = f"http://localhost:{config.frontend_port}"
918+
self.frontend_url = "http://localhost:{1}".format(
919+
*self.frontend_server.socket.getsockname()
920+
)
929921
self.frontend_server.serve_forever()
930922

931923
def _start_frontend(self):
932924
# Set up the frontend.
933925
with chdir(self.app_path):
934-
backend_host, backend_port = self._poll_for_servers().getsockname()
935926
config = reflex.config.get_config()
936-
config.backend_port = backend_port
937927
config.api_url = "http://{0}:{1}".format(
938-
backend_host,
939-
backend_port,
928+
*self._poll_for_servers().getsockname(),
940929
)
941930
reflex.reflex.export(
942931
zipping=False,

reflex/utils/console.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from __future__ import annotations
44

5-
import os
6-
75
from rich.console import Console
86
from rich.progress import MofNCompleteColumn, Progress, TimeElapsedColumn
97
from rich.prompt import Prompt
@@ -14,7 +12,7 @@
1412
_console = Console()
1513

1614
# The current log level.
17-
_LOG_LEVEL = LogLevel.DEFAULT
15+
_LOG_LEVEL = LogLevel.INFO
1816

1917
# Deprecated features who's warning has been printed.
2018
_EMITTED_DEPRECATION_WARNINGS = set()
@@ -63,9 +61,6 @@ def set_log_level(log_level: LogLevel):
6361
raise ValueError(f"Invalid log level: {log_level}") from ae
6462

6563
global _LOG_LEVEL
66-
if log_level != _LOG_LEVEL:
67-
# Set the loglevel persistently for subprocesses
68-
os.environ["LOGLEVEL"] = log_level.value
6964
_LOG_LEVEL = log_level
7065

7166

scripts/integration.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ if [ -f /proc/$pid/winpid ]; then
3434
echo "Windows detected, passing winpid $pid to port waiter"
3535
fi
3636

37-
python scripts/wait_for_listening_port.py $check_ports --timeout=900 --server-pid "$pid" $WAIT_FOR_LISTENING_PORT_ARGS
37+
python scripts/wait_for_listening_port.py $check_ports --timeout=900 --server-pid "$pid"

scripts/wait_for_listening_port.py

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
from concurrent.futures import ThreadPoolExecutor, as_completed
1111
from typing import Tuple
1212

13-
import httpx
14-
1513
# psutil is already a dependency of Reflex itself - so it's OK to use
1614
import psutil
1715

@@ -25,7 +23,6 @@ def _pid_exists(pid):
2523
return pid in psutil.pids()
2624

2725

28-
# Not really used anymore now that we actually check the HTTP response.
2926
def _wait_for_port(port, server_pid, timeout) -> Tuple[bool, str]:
3027
start = time.time()
3128
print(f"Waiting for up to {timeout} seconds for port {port} to start listening.") # noqa: T201
@@ -44,70 +41,25 @@ def _wait_for_port(port, server_pid, timeout) -> Tuple[bool, str]:
4441
time.sleep(5)
4542

4643

47-
def _wait_for_http_response(port, server_pid, timeout, path) -> Tuple[bool, str, str]:
48-
start = time.time()
49-
if path[0] != "/":
50-
# This is a hack for passing the path on windows without a leading slash
51-
# which mangles it https://stackoverflow.com/a/49013604
52-
path = "/" + path
53-
url = f"http://localhost:{port}{path}"
54-
print(f"Waiting for up to {timeout} seconds for {url} to return HTTP response.") # noqa: T201
55-
while True:
56-
try:
57-
if not _pid_exists(server_pid):
58-
return False, f"Server PID {server_pid} is not running.", ""
59-
response = httpx.get(url, timeout=0.5)
60-
response.raise_for_status()
61-
return (
62-
True,
63-
f"{url} returned response after {time.time() - start} seconds",
64-
response.text,
65-
)
66-
except Exception as exc: # noqa: PERF203
67-
if time.time() - start > timeout:
68-
return (
69-
False,
70-
f"{url} still returning errors after {timeout} seconds: {exc!r}.",
71-
"",
72-
)
73-
time.sleep(5)
74-
75-
7644
def main():
7745
"""Wait for ports to start listening."""
7846
parser = argparse.ArgumentParser(description="Wait for ports to start listening.")
7947
parser.add_argument("port", type=int, nargs="+")
8048
parser.add_argument("--timeout", type=int, required=True)
8149
parser.add_argument("--server-pid", type=int)
82-
parser.add_argument("--path", type=str, default="/")
8350
args = parser.parse_args()
84-
start = time.time()
8551
executor = ThreadPoolExecutor(max_workers=len(args.port))
8652
futures = [
87-
executor.submit(
88-
_wait_for_http_response,
89-
p,
90-
args.server_pid,
91-
args.timeout,
92-
args.path,
93-
)
53+
executor.submit(_wait_for_port, p, args.server_pid, args.timeout)
9454
for p in args.port
9555
]
96-
base_content = None
9756
for f in as_completed(futures):
98-
ok, msg, content = f.result()
57+
ok, msg = f.result()
9958
if ok:
10059
print(f"OK: {msg}") # noqa: T201
101-
if base_content is None:
102-
base_content = content
103-
else:
104-
assert (
105-
content == base_content
106-
), f"HTTP responses are not equal {content!r} != {base_content!r}."
10760
else:
10861
print(f"FAIL: {msg}") # noqa: T201
10962
exit(1)
110-
print(f"OK: All HTTP responses are equal after {time.time() - start} sec.") # noqa: T201
11163

11264

11365
if __name__ == "__main__":

tests/integration/init-test/in_docker_test_script.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ source ~/venv/bin/activate
2929
pip install -U pip
3030

3131
echo "Installing reflex from local repo code"
32-
pip install '/reflex-repo[proxy]'
32+
pip install /reflex-repo
3333

3434
redis-server &
3535

0 commit comments

Comments
 (0)