minimal-fastapi-postgres-template
minimal-fastapi-postgres-template copied to clipboard
How to show the docs in browser?
Hello
I'm running the backend locally directly using
uvicorn app.main:app --reload
with the output
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) INFO: Started reloader process [84691] using statreload INFO: Started server process [84702] INFO: Waiting for application startup. INFO: Application startup complete.
How can I see the specification in the browser?
Hi, it's directly localhost:8000
.
You can change that behaviour in main.py
using docs_url
, I belive default one in FastAPI is /docs
if I remember correctly, this is just my opinionated choice here.
https://github.com/rafsaf/minimal-fastapi-postgres-template/blob/e820c9bae17c19d13db3055400450877b26647be/%7B%7Bcookiecutter.project_name%7D%7D/template_minimal/app/main.py#L10-L16
Hello, thanks for the reply. Indeed, I was trying http://127.0.0.1:8000
and receiving Invalid host header
message.
@smolendawid
Umm that's another thing if you dont mind.
It's because threre is trusted host middleware from fastapi, it's to prevent host header attacks and by you control it like everything else by env variable, if you put 127.0.0.1
to the list, it would work then.
ALLOWED_HOSTS=["localhost"]
https://github.com/rafsaf/minimal-fastapi-postgres-template/blob/e820c9bae17c19d13db3055400450877b26647be/%7B%7Bcookiecutter.project_name%7D%7D/template_minimal/app/main.py#L28-L29
Anyway I think your concerns are quite correct, I will try to update README a bit with maybe extra libraries upgrade, didn't find anything about this topic in current README and now I see this can be misleading indeed, let's keep issue open if that's something possible for you, so I will not forget.
@smolendawid
Umm that's another thing if you dont mind.
It's because threre is trusted host middleware from fastapi, it's to prevent host header attacks and by you control it like everything else by env variable, if you put
127.0.0.1
to the list, it would work then.ALLOWED_HOSTS=["localhost"]
https://github.com/rafsaf/minimal-fastapi-postgres-template/blob/e820c9bae17c19d13db3055400450877b26647be/%7B%7Bcookiecutter.project_name%7D%7D/template_minimal/app/main.py#L28-L29
Just add it to the .env
then and make it clear in the README what the docs URI is
What's the use of a template if it doesn't work?
Added 127.0.0.1
to .env and mentioned it in docs, sorry about that, im used to write localhost like an automat