question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Unable to correctly reverse proxy FastAPI

See original GitHub issue

Describe the bug

When using FastAPI behind a proxy that adds path elements like /api/1.0/, there is no way to correctly display the swagger

To Reproduce

  1. Configure a reverse proxy to send /api/1.0/ to your FastAPI server
  2. access swagger for the API
  3. Observe that all your objects are prefixed with /api/1.0

See screenshot

Expected behavior

/api/1.0 should not be part of API documentation.

OpenAPI documents this here

There should be a way to configure Server URL to /api/1.0 like indicated in the examples.

Screenshots

image

Environment

  • OS: alpine docker image
  • FastAPI Version 0.54.1
  • Python version 3.7.3

Additional context

Using Traefik as reverse proxy. Traefik like other proxies, has the ability to either : Pass the request as-is with /api/1.0/, or strip the part from the URL and put it in the X-Forwarded-Prefix header. Maybe that could be used as the server URL for Swagger.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
tiangolocommented, Jul 10, 2020

This was fixed/implemented by @rkbeatss in https://github.com/tiangolo/fastapi/pull/1596. 🎉

Available in FastAPI version 0.59.0. 🚀

New docs here: https://fastapi.tiangolo.com/advanced/behind-a-proxy/#additional-servers

3reactions
tiangolocommented, Jun 12, 2020

Ah, you are right, I didn’t interpret your original issue description correctly.

You expected it to not contain the prefix and still work.

I have to investigate how the servers would interact with the rest.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Behind a Proxy - FastAPI
Having a proxy with a stripped path prefix, in this case, means that you could declare a path at /app in your code,...
Read more >
can't see fastAPI documentation with 2 main.py and 1 nginx ...
Using nginx as a reverse proxy, I can call the APIs with their own endpoints under a single port (8000), then nginx will...
Read more >
tiangolo/fastapi - Gitter
This application is started and stopped per user task session to a particular port. I would like to use fastapi as a reverse...
Read more >
Deploying Gunicorn — Gunicorn 20.1.0 documentation
Without this buffering Gunicorn will be easily susceptible to denial-of-service attacks. You can use Hey to check if your proxy is behaving properly....
Read more >
Deploying an Asynchronous FastAPI on NGINX Unit
Traditional deployment methods use web servers behind a reverse proxy server, thus increasing the routing process. Nginx Unit is an ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found