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 2c69a10f0e
commit ecc48547d1

6
app.py
View file

@ -505,7 +505,7 @@ class Handler(BaseHTTPRequestHandler):
f"</form>" f"</form>"
f"<h2>bookmarklet</h2>" 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>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"<p>{msg}</p>"
f'<a href="/">back</a>' f'<a href="/">back</a>'
) )
@ -520,5 +520,5 @@ class Handler(BaseHTTPRequestHandler):
if __name__ == "__main__": if __name__ == "__main__":
init_db() init_db()
print("running on http://localhost:5001") print("running on http://0.0.0.0:5001")
HTTPServer(("localhost", 5001), Handler).serve_forever() HTTPServer(("0.0.0.0", 5001), Handler).serve_forever()