Skip to content

Share localhost / FastAPI

Share a FastAPI dev server at a public URL

fastapi dev listens on 127.0.0.1:8000, and whk share 8000 gives it an HTTPS link. There is no host check to pass. The catch is Uvicorn's proxy headers, which are on by default and change where redirects go.

# terminal 1: the dev server
fastapi dev --no-proxy-headers

# terminal 2: the link
whk share 8000

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

FastAPI at a glance

Dev server
fastapi dev --no-proxy-headers, port 8000
Share it
whk share 8000
Setting to add
None for the host. Start the server with --no-proxy-headers while sharing, so its redirects are ones the link can send back.
Without it
A request for /items/ when the route is /items redirects to https://localhost:8000/items, which the visitor's browser cannot open.
Hot reload
fastapi dev reloads the server when your code changes. It does not refresh the browser.
URLs and cookies
request.url and url_for use the Host header, so they say localhost:8000. Link with paths (url_for(...).path); /docs already loads /openapi.json by path.

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

Why redirects go to https://localhost:8000

Uvicorn applies X-Forwarded-Proto and X-Forwarded-For from addresses it trusts, and by default it trusts 127.0.0.1 and ::1. whk connects from your own machine, so the scheme becomes https and the client address becomes the visitor's. Uvicorn does not read X-Forwarded-Host, so the host stays localhost:8000.

The mix shows in anything absolute. Starlette's trailing-slash redirect, the one that sends /items/ to /items, answers with Location: https://localhost:8000/items. The link rewrites redirects to http://localhost:8000, which is what a local server normally sends, but not this https form, so the visitor's browser is sent to its own machine.

Turn the proxy headers off while sharing. The redirect is then http://localhost:8000/items, and the link returns it as https://<name>.sharehooks.cc/items:

fastapi dev main.py --no-proxy-headers
whk share 8000

The same flag exists on uvicorn main:app --reload --no-proxy-headers. Without proxy headers request.client.host is 127.0.0.1; the visitor's address is still in the X-Forwarded-For header if you need it.

url_for, templates and /docs

request.url_for("static", path="/app.css") returns a full URL built from the Host header: http://localhost:8000/static/app.css. In a template that is a stylesheet the visitor's browser cannot load. Use the path instead, which is the same on localhost and on the link: url_for("static", path="/app.css").path.

The interactive docs need nothing. /docs asks for /openapi.json by path, and the schema has no servers entry unless you set a root path, so Swagger UI calls your API on whatever origin the page was opened from. Its own scripts and styles come from a CDN, not through the link.

Hosts, CORS and WebSockets

FastAPI adds no host check. If your app uses TrustedHostMiddleware, it compares the Host header, so allowed_hosts=["localhost"] keeps passing; a host it does not know gets 400 with Invalid host header.

A page served by the app and calling the same app is same-origin on the link, so CORSMiddleware is not involved. A separate frontend on another port is a second share and a second origin: allow that origin in CORSMiddleware, or serve both from one port. WebSocket routes pass through the link like any other request.

FastAPI questions

Sources

The FastAPI settings and messages on this page are from the official documentation and source for FastAPI 0.162, 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 FastAPI app

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

or sign up with email

No credit card