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

Failed to access static files with subapps. #86

Open
momocow opened this issue Mar 6, 2020 · 0 comments
Open

Failed to access static files with subapps. #86

momocow opened this issue Mar 6, 2020 · 0 comments

Comments

@momocow
Copy link

momocow commented Mar 6, 2020

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.

app.router.add_static(static_path, static_files)

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",)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant