Bind to 0.0.0.0 and use dynamic Host header for bookmarklet

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.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Derick Phan 2026-03-24 20:45:14 -07:00
parent 3bd8601c63
commit c30fccb7a1
No known key found for this signature in database

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()