From a2a737e21d2b2e78dde0c23586ad37473824b37f Mon Sep 17 00:00:00 2001 From: retoor Date: Mon, 26 Oct 2026 04:15:09 +0100 Subject: [PATCH] fix: bind living example on all interfaces, default port 8000 The example server bound 127.0.0.1 only, so it was unreachable from other hosts, and defaulted to 8080. It now binds 0.0.0.0 on 8000 (README, Makefile deploy and locust targets updated to match). Also: a leading --flag no longer gets parsed as the port, so 'living-server --no-locust' starts instead of exiting with 'bad port'. Co-Authored-By: Claude Haiku 5.5 --- example/README.md | 7 ++++--- example/example.mk | 4 ++-- example/locustfile.py | 4 ++-- example/main.cpp | 12 ++++++------ 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/example/README.md b/example/README.md index 4b13419..cbb61e3 100644 --- a/example/README.md +++ b/example/README.md @@ -7,10 +7,11 @@ Run it: ```sh make -f example/example.mk example -./build/example/living-server 8080 +./build/example/living-server 8000 ``` -Open `http://127.0.0.1:8080/` and click through the matrix; `/stats` has the +The server listens on all interfaces. Open `http://127.0.0.1:8000/` (or the +machine's LAN address) and click through the matrix; `/stats` has the charts (Chart.js is embedded in the binary, no CDN). Narrow the window to 360px: the top nav collapses into a dropdown menu. @@ -29,7 +30,7 @@ routes (`/hello/{name}`, `/di/resolve/{name}`, `/tenancy/t/{tenant}/whoami`, ```sh pip install locust -locust -f example/locustfile.py --host http://127.0.0.1:8080 +locust -f example/locustfile.py --host http://127.0.0.1:8000 ``` Open the Locust web UI at `http://localhost:8089` (linked as `locust` in diff --git a/example/example.mk b/example/example.mk index 5348494..777c805 100644 --- a/example/example.mk +++ b/example/example.mk @@ -132,7 +132,7 @@ example-test: example example-locust: python3 $(EXAMPLE_DIR)/check_locust_coverage.py - locust -f $(EXAMPLE_DIR)/locustfile.py --host $${LOCUST_HOST:-http://127.0.0.1:8080} --headless -u $${LOCUST_USERS:-10} -r $${LOCUST_RATE:-2} -t $${LOCUST_TIME:-30s} + locust -f $(EXAMPLE_DIR)/locustfile.py --host $${LOCUST_HOST:-http://127.0.0.1:8000} --headless -u $${LOCUST_USERS:-10} -r $${LOCUST_RATE:-2} -t $${LOCUST_TIME:-30s} example-clean: rm -rf $(EXAMPLE_BUILD) @@ -140,7 +140,7 @@ example-clean: # Deploy: loopback single binary (AGENTS.md "Deploy"). Restarts the server from # build/ with a pid file; fails if it is not healthy within 15 s. Runs from # the repo root so .env.json(.local) and example/static resolve. -EXAMPLE_PORT ?= 8080 +EXAMPLE_PORT ?= 8000 EXAMPLE_RUN = $(EXAMPLE_BUILD)/run example-deploy: example diff --git a/example/locustfile.py b/example/locustfile.py index 81dd1d5..0263acc 100644 --- a/example/locustfile.py +++ b/example/locustfile.py @@ -3,9 +3,9 @@ Run against a live server: make -f example/example.mk example - ./build/example/living-server 8080 & + ./build/example/living-server 8000 & pip install locust - locust -f example/locustfile.py --host http://127.0.0.1:8080 + locust -f example/locustfile.py --host http://127.0.0.1:8000 Then open the Locust web UI at http://localhost:8089. """ diff --git a/example/main.cpp b/example/main.cpp index 9660b83..19db87b 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -1,5 +1,5 @@ -// Living example server entry: serves the demo app on loopback. -// Usage: living-server [port] [--no-locust] (default port 8080) +// Living example server entry: serves the demo app on all interfaces. +// Usage: living-server [port] [--no-locust] (default port 8000) // The Locust load-test UI (web UI on 8089) runs as a process worker under // the real molo::supervisor::Supervisor: started with the server, // restarted on crash, stopped with it. @@ -24,14 +24,14 @@ void on_signal(int) { g_stop = true; } } // namespace int main(int argc, char** argv) { - int port = 8080; + int port = 8000; bool with_locust = true; for (int i = 2; i < argc; ++i) { if (std::string(argv[i]) == "--no-locust") with_locust = false; } std::signal(SIGINT, on_signal); std::signal(SIGTERM, on_signal); - if (argc > 1) { + if (argc > 1 && std::string(argv[1]).rfind("--", 0) != 0) { try { port = std::stoi(argv[1]); } catch (...) { @@ -43,11 +43,11 @@ int main(int argc, char** argv) { auto app = molo::example::app::build_application(services); molo::example::fw::Server server(app); server.set_stats(services.stats); - if (!server.start("127.0.0.1", port)) { + if (!server.start("0.0.0.0", port)) { std::cerr << "bind failed\n"; return 1; } - std::cout << "living example on http://127.0.0.1:" << server.port() << "\n"; + std::cout << "living example on http://0.0.0.0:" << server.port() << "\n"; molo::common::SystemClock clock; molo::supervisor::Supervisor supervisor( clock, std::make_shared());