Skip to content

Static asset URLs use absolute host:port causing 404 when binding to 0.0.0.0 #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sternma opened this issue May 19, 2025 · 0 comments

Comments

@sternma
Copy link

sternma commented May 19, 2025

Description

When running Textual-Serve bound to 0.0.0.0, the landing‐page template inlines all static asset URLs (CSS/JS/images) using the configured host or public_url. If you pass host="0.0.0.0" (or forget to set public_url), every request for /static/... goes to http://0.0.0.0:8000/static/..., which is not routable, and assets fail to load.

Steps to Reproduce

  1. Install textual-serve==1.1.2 in a project.
  2. Create a main.py containing:
    from textual_serve.server import Server
    
    server = Server("python3 your_app.py", host="0.0.0.0")
    server.serve(debug=True)
  3. Run:
    python3 main.py
  4. Open a browser to http://<your-machine-IP>:8000/.
  5. Observe in DevTools → Network that requests for xterm.css, textual.js, etc. are targeting http://0.0.0.0:8000/static/... and failing.

Actual Behavior

  • Asset requests are issued to 0.0.0.0:8000, which refuses connections.
  • Landing page shows placeholder panel without styling or “Run ▶︎” button (static assets never load).

Expected Behavior

Assets should either:

  1. Be served via relative URLs (e.g. /static/js/textual.js) so they load from the same origin the browser requested, or
  2. If an absolute URL is required, fall back to using the incoming Host header when public_url is unset, rather than the bind address.

Environment

  • textual-serve version: 1.1.2
  • Python: 3.10.11
  • Platform: Ubuntu 22.04 LTS (Docker container)
  • Browser: Chrome 135.0.0.0 on macOS 10.15.7

Proposed Solution

Update the Jinja template (app_index.html) so that static assets use relative paths by default:

<!-- before -->
<link rel="stylesheet" href="{{ config.static.root }}/css/xterm.css">

<!-- after -->
<link rel="stylesheet" href="/static/css/xterm.css">

Alternatively, detect when public_url is the generic bind address (0.0.0.0 or ::) and fall back to Host header–based URL generation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant