Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to show docs with nginx url prefix set? #606

Open
almosthuman56 opened this issue Feb 15, 2024 · 1 comment
Open

How to show docs with nginx url prefix set? #606

almosthuman56 opened this issue Feb 15, 2024 · 1 comment
Labels

Comments

@almosthuman56
Copy link

almosthuman56 commented Feb 15, 2024

I have project which uses flask-smorest and when I run it locally it shows docs on url /docs/swagger. But on my production server I have in nginx setup to append api/ prefix on each url and then docs are not showing because flask-smorest expects openapi.json on docs/openapi.json but mine nginx append api/ and openapi.json is visible on url api/docs/openapi.json so I keep getting error:

image

So basically how to setup configuration so it loads docs? Here are mine configuration in project for flask-smorest:


app = Flask(__name__)
app.config["API_TITLE"] = "Test API"
app.config["API_VERSION"] = "v1"
app.config["OPENAPI_VERSION"] = "3.0.2"
app.config["OPENAPI_URL_PREFIX"] = "/docs"
app.config["OPENAPI_REDOC_PATH"] = "/redoc"
app.config["OPENAPI_REDOC_URL"] = "https://cdn.jsdelivr.net/npm/redoc@2.0.0-rc.30/bundles/redoc.standalone.js"
app.config["OPENAPI_SWAGGER_UI_PATH"] = "/swagger"
app.config["OPENAPI_SWAGGER_UI_URL"] = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@3.25.5/"

api = Api(app)
api.register_blueprint(blp_test)
@lafrech
Copy link
Member

lafrech commented Apr 18, 2024

We most often deploy with nginx + uwsgi and setup uswgi to prepend API URLs with /api/v1 like explained here. I believe this is transparent to Flask so we don't have to do anything for this to work.

Out of curiosity, I'd try to use APPLICATION_ROOT, but I'm not sure it is the right thing to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants