minimal-fastapi-postgres-template icon indicating copy to clipboard operation
minimal-fastapi-postgres-template copied to clipboard

How to show the docs in browser?

Open smolendawid opened this issue 2 years ago • 5 comments

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?

smolendawid avatar Aug 23 '22 06:08 smolendawid

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

rafsaf avatar Aug 23 '22 09:08 rafsaf

Hello, thanks for the reply. Indeed, I was trying http://127.0.0.1:8000 and receiving Invalid host header message.

smolendawid avatar Aug 23 '22 17:08 smolendawid

@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

rafsaf avatar Aug 23 '22 21:08 rafsaf

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.

rafsaf avatar Aug 23 '22 21:08 rafsaf

@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?

pynchia avatar Sep 11 '22 10:09 pynchia

Added 127.0.0.1 to .env and mentioned it in docs, sorry about that, im used to write localhost like an automat

rafsaf avatar Oct 19 '22 19:10 rafsaf