bound to 0.0.0.0, dynamic Host header

Makes the server accessible from other devices on the network
instead of only localhost. The bookmarklet now uses the Host header
from the request so it works regardless of how the server is accessed.
This commit is contained in:
blankie 2026-03-24 20:45:14 -07:00
parent 39d676b589
commit 625f91c4f4
2 changed files with 3 additions and 3 deletions

6
app.py
View file

@ -505,7 +505,7 @@ class Handler(BaseHTTPRequestHandler):
f"</form>"
f"<h2>bookmarklet</h2>"
f"<p>Drag this link to your bookmarks bar. Click it on any page to index it instantly.</p>"
f'<p><a href="javascript:void(fetch(\'http://localhost:5001/bookmark?url=\'+encodeURIComponent(location.href)).then(r=>r.text()).then(t=>alert(t)).catch(()=>alert(\'tinyweb not running\')))">+ save to {esc(name)}</a></p>'
f'<p><a href="javascript:void(fetch(\'http://{esc(self.headers.get("Host", "localhost:5001"))}/bookmark?url=\'+encodeURIComponent(location.href)).then(r=>r.text()).then(t=>alert(t)).catch(()=>alert(\'tinyweb not running\')))">+ save to {esc(name)}</a></p>'
f"<p>{msg}</p>"
f'<a href="/">back</a>'
)
@ -520,5 +520,5 @@ class Handler(BaseHTTPRequestHandler):
if __name__ == "__main__":
init_db()
print("running on http://localhost:5001")
HTTPServer(("localhost", 5001), Handler).serve_forever()
print("running on http://0.0.0.0:5001")
HTTPServer(("0.0.0.0", 5001), Handler).serve_forever()

BIN
index.db

Binary file not shown.