Skip to content

Share localhost / Flask

Share a Flask app at a public URL

flask run listens on 127.0.0.1:5000, and whk share 5000 gives it an HTTPS link. Flask accepts any host, so there is nothing to allow; the two things to know are how external URLs are built and what debug mode shows a visitor.

# terminal 1: the dev server
flask run

# terminal 2: the link
whk share 5000

The link is https://<name>.sharehooks.cc and works until you press Ctrl-C. No whk yet? Install it and log in, which takes a minute.

Start free:
or sign up with email

Flask at a glance

Dev server
flask run, port 5000
Share it
whk share 5000
Setting to add
None. Flask checks no host by default, and TRUSTED_HOSTS, if you set it, sees localhost.
Without it
Nothing fails. External URLs from url_for(..., _external=True) read http://localhost:5000/... until ProxyFix is added.
Hot reload
flask run --debug restarts the server when your Python code changes. It does not refresh the browser.
URLs and cookies
ProxyFix makes request.url, the scheme and the client address follow X-Forwarded-*. The session cookie has no domain by default and works on the link.

Your dev server gets each request with Host: localhost:5000; the public name travels in X-Forwarded-Host, with X-Forwarded-Proto: https. What your server sees has the rest.

Pages load without any setting

Flask's docs put it plainly: by default the app does not know which hosts it may be reached through and treats any host as valid. Through the link it sees Host: localhost:5000, so even an app that sets TRUSTED_HOSTS = ["localhost"] keeps answering.

Port 5000 is taken on recent macOS versions by the AirPlay Receiver service. If flask run says the address is in use, start it with flask run --port 5001 and share that port.

External URLs with ProxyFix

url_for('page') returns a path, which works anywhere. url_for('page', _external=True), request.url and request.host use the Host header, so through the link they say http://localhost:5000. To build links for an email or an OAuth callback, wrap the app in Werkzeug's ProxyFix, which applies the forwarded headers:

app.py

from werkzeug.middleware.proxy_fix import ProxyFix

# One proxy (the link) sets each of these headers
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1)

With it, request.url reads https://<name>.sharehooks.cc/... and request.remote_addr is the visitor's address. If you also use TRUSTED_HOSTS, add ".sharehooks.cc" to it, because the host Flask validates is now the forwarded one; otherwise every request answers 400 with Host '<name>.sharehooks.cc' is not trusted. Apply ProxyFix only while a proxy is in front: Flask's docs call a wrong configuration a security issue.

Debug mode and the Werkzeug debugger

flask run --debug shows an interactive debugger in the browser when a request raises, and its console runs Python on your machine. Werkzeug only serves the console to trusted hosts, localhost among them, and it decides by the Host header, which through any share is localhost.

So the link itself keeps the console back: requests for the debugger's console and its commands are refused with a page of its own and never reach your app. The traceback page still shows, with your source code in it. Share without --debug, or behind whk share 5000 --password.

Forms and sessions

Flask has no CSRF protection of its own, so there is no origin check to satisfy; an extension that adds one brings its own rules. The session cookie is set with HttpOnly and no domain, so the visitor's browser keeps it for the link. Leave SESSION_COOKIE_DOMAIN unset: a cookie set for another domain is dropped on the way out.

Flask questions

Sources

The Flask settings and messages on this page are from the official documentation and source for Flask 3.1, read on 12 November 2026. What the link does to a request is from the whk share docs.

Other frameworks

All 14 framework guides

Send someone your Flask app

Sign up free, install the CLI and run whk share 5000.

or sign up with email

No credit card