Skip to content

Proxy SignalR through nginx and avoid stale web app config caching - #680

Merged
LarsLaskowski merged 2 commits into
mainfrom
fix/web-app-same-origin-proxy
Nov 29, 2026
Merged

LarsLaskowski merged 2 commits into
mainfrom
fix/web-app-same-origin-proxy

Conversation

@LarsLaskowski

@LarsLaskowski LarsLaskowski commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Pull Request

📖 Description

When the web interface is exposed publicly (for example via a Cloudflare Tunnel), setting F1SERVER_URL to an internal service address makes the browser call the backend directly. Browsers block these requests from a public origin to a private network address, so the site only works inside the local network.

The web app's nginx already proxies /api and /live to the service, so leaving F1SERVER_URL empty makes the browser use relative, same-origin URLs. This PR completes that setup:

  • F1ServerApp/conf/default.conf:
    • forwards the WebSocket Upgrade/Connection headers on /live and raises the read timeout, so SignalR can use WebSockets through the proxy. Without them the WebSocket handshake fails and SignalR falls back to another transport.
    • disables response buffering on /live, so the Server-Sent Events fallback also works through nginx and Cloudflare.
    • repeats the common proxy headers in /live, because nginx does not inherit proxy_set_header once a location defines its own.
    • serves index.html and assets/env.js with Cache-Control: no-cache, so configuration changes reach browsers immediately instead of stale cached copies being used. Hashed bundles keep their normal caching.
  • README.md: recommends leaving F1SERVER_URL empty, notes that only the web app container needs to be exposed, corrects the compose example to use the container port 80 instead of the published port 4820 when addressing the service by its compose service name, and explains the user-defined network requirement for name resolution.

Fix, no breaking change. Existing setups with F1SERVER_URL set keep working.

🎫 Issues

👩‍💻 Reviewer Notes

Suggested smoke test: run both containers with F1SERVER_URL unset, F1SERVER_HOST set to the service name and F1SERVER_PORT set to 80. Open the web app via a public hostname or tunnel and confirm that the API calls and the /live SignalR connection use the web app's origin, and that the SignalR transport is WebSockets. Also check that index.html and assets/env.js are returned with Cache-Control: no-cache.

📑 Test Plan

No automated tests are affected; the change is limited to the nginx configuration and documentation.

✅ Checklist

General

  • I have added tests for my changes.
  • I have tested my changes.
  • I have updated the project documentation to reflect my changes.
  • I have read the CONTRIBUTING documentation and followed the project's code style guidelines.

⏭ Next Steps

  • Consider removing F1SERVER_URL entirely once same-origin proxying is the only supported setup.
  • Consider resolving F1SERVER_HOST at request time (Docker DNS resolver) so the web app container starts even while the service is unavailable.

The web app nginx now forwards WebSocket upgrade headers on /live so SignalR works through reverse proxies and Cloudflare Tunnels. The README recommends leaving F1SERVER_URL empty so the browser calls /api and /live on its own origin, and corrects the example port to the container port 80.
SignalR can fall back to Server-Sent Events, which only work through nginx and Cloudflare without response buffering. index.html and assets/env.js are now served with Cache-Control no-cache so configuration changes reach browsers immediately. The README explains the network requirements for addressing the service by name.
@LarsLaskowski LarsLaskowski changed the title Proxy SignalR WebSockets and document same-origin web app setup Proxy SignalR through nginx and avoid stale web app config caching Nov 29, 2026
@sonarqubecloud

Copy link
Copy Markdown

@LarsLaskowski
LarsLaskowski merged commit 071586c into main Nov 29, 2026
7 checks passed
@LarsLaskowski
LarsLaskowski deleted the fix/web-app-same-origin-proxy branch November 29, 2026 20:08
@LarsLaskowski LarsLaskowski added the robustness Increased robustness label Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

robustness Increased robustness

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant