fastapi-freeze blog A FastAPI app, frozen to static files.

Hosting under a subpath

This site is served at https://listfold.github.io/fastapi-freeze/, not at the root of a domain. The file for this post is posts/hosting-under-a-subpath/index.html, but its URL starts with /fastapi-freeze/.

The prefix depends on where the site is deployed, not on the app, so it is a build option. The GitHub Actions workflow for this site runs:

fastapi-freeze main:app -o dist --strict --base-path /fastapi-freeze

fastapi-freeze renders every page the way uvicorn --root-path /fastapi-freeze would. The templates build links with url_for(...).path, so each link carries the prefix, while the files keep their route paths:

<a href="{{ url_for('post', slug=post.slug).path }}">{{ post.title }}</a>

--strict also checks every link in every frozen page. A hard-coded /posts/... link without the prefix would fail the build here, instead of returning 404 on GitHub Pages.

All posts