Code Monkey home page Code Monkey logo

Comments (7)

scratchmex avatar scratchmex commented on April 28, 2024 2

This should be fixed (fixable) with the new openapi_prefix parameter, check the new docs to run FastAPI behind a proxy: https://fastapi.tiangolo.com/tutorial/sub-applications-proxy/

The new link is https://fastapi.tiangolo.com/advanced/sub-applications-proxy. This helped me, thanks.

from fastapi.

tiangolo avatar tiangolo commented on April 28, 2024

Does the basic tutorial work for you?

Try first with the basic one, as is. From the main page.

A main.py with:

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def read_root():
    return {"Hello": "World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: str = None):
    return {"item_id": item_id, "q": q}

Then:

uvicorn main:app --debug

And then: http://127.0.0.1:8000/docs

Does that work?

from fastapi.

medecau avatar medecau commented on April 28, 2024

Thanks for you reply. The above does work.

I have tested locally with caddy server to mimic what we have in prod.

localhost:8080
proxy /api 127.0.0.1:8000 {
	without /api
}

The problem seems to be that in prod the api sits behind an Ngingx reverse proxy. That is the path on the frontend does not match the path on the backend.

from fastapi.

tiangolo avatar tiangolo commented on April 28, 2024

This should be fixed (fixable) with the new openapi_prefix parameter, check the new docs to run FastAPI behind a proxy: https://fastapi.tiangolo.com/tutorial/sub-applications-proxy/

from fastapi.

medecau avatar medecau commented on April 28, 2024

openapi_prefix does indeed fix the issue. And thank you for the documentation.

from fastapi.

tiangolo avatar tiangolo commented on April 28, 2024

Awesome! Thanks for reporting back.

from fastapi.

github-actions avatar github-actions commented on April 28, 2024

Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs.

from fastapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.