Failed to access static files with subapps.
momocow opened this issue · 0 comments
Hello, I have set up the apispec and visited the web page with browser and I found that all swagger static files are 404 not found.
For example, I have set up the apispec like the following snippet, where app
is a subapp which is registered to the main app with main_app.add_subapp("/v2/", app)
.
setup_aiohttp_apispec(app=app, # app is an instance of subapp
title="My Documentation",
version="v2",
url="/docs/swagger.json",
static_path="/static/swagger",
swagger_path="/docs",)
Since the subapp is registered under /v2/
, the web page can be visited at http://example.com/v2/docs
with swagger_path
set to /docs
.
But all urls in static files are rendered with absolute path, /static/swagger
, which caused 404 since all static files are registered to the subapp, app
, under /v2/static/swagger
.
where app
is served as the subapp, /v2/
.
Maybe it's better to separate the static path used in the template from the one registered to the app?
That is,
setup_aiohttp_apispec(app=app, # app is an instance of subapp
title="My Documentation",
version="v2",
url="/docs/swagger.json",
static_base_url="/v2/static/swagger", # used in the template
static_path="/static/swagger", # used to register the static resource
swagger_path="/docs",)