fastapi-azure-function-apim icon indicating copy to clipboard operation
fastapi-azure-function-apim copied to clipboard

/api not taken into account

Open MiguelElGallo opened this issue 1 year ago • 1 comments

Hello @pamelafox , I was wondering if you can give me hand with something:

I'm using: server = FastAPI( servers=[{"url": "/api", "description": "Endpoints for the API"}], root_path="/public", root_path_in_servers=False, title="Demo FastAPI function", lifespan=lifespan, )

This solves the location of the openapi.json file, thanks a and great!

But then I have a router: router = APIRouter(prefix="/v1/control_table", tags=["control_table"])

In the UI show like this:

fastapitest

In 1 you can see there no /api in the URL, but in 2 you can see there is /api in the url, which then fails.

The endpoint is deployed without /api, but the UI thinks there is /api prefix.

Do you have any hints how to solve this?

Thanks! MIguel PS.: I have been trying with the prefix and when adding the router, but with no luck.

MiguelElGallo avatar May 15 '24 13:05 MiguelElGallo

Sorry for delay, I haven't revisited this project in a while.

It's adding the /api due to this line:

        servers=[{"url": "/api", "description": "API"}],

That's intentional since this architecture sends all /api/ requests through APIM, which requires a subscription key on them, and then forwards them to the app.

Are you saying the issue is that it's then not being recognized by FastAPI? There might be some bad interaction between Router and the FastAPI config.

pamelafox avatar Nov 07 '24 21:11 pamelafox