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

Localhost url constructed without port number in redoc and swagger templates #103

Closed
luisgc93 opened this issue Jun 20, 2020 · 3 comments
Closed

Comments

@luisgc93
Copy link

When building the url_name in the swagger and redoc views, reverse uses the current request in the context. If we run our project locally, that would be localhost in the app container but localhost:port_number for the instance outside the app container:

{'url_name': reverse(self.url_name, request=request)},

To reproduce, install drf-spectacular v0.9.7 or above and go to your project's doc page on localhost e.g. localhost:8030/mydocs/redoc/. The following error will show up (notice the missing port number in the request):

Error downloading http://localhost/docs/schema/ Failed to fetch
Stack trace
Error: Error downloading http://localhost/docs/schema/ 
Failed to fetch
    at https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js:63:6628
    at https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js:122:36080

TypeError: Failed to fetch

ReDoc Version: 2.0.0-rc.30
Commit: 5bace30

When using v0.9.6 the normal response is rendered successfully.

@tfranzel
Copy link
Owner

that was an unintended side effect of a previous change to versioning.

plain reverse generates a relative URL. reverse with the request parameter generates an absolute URL. unfortunately, the request is required to make the versioning work correctly.

the "proper" way to do django with a reverse proxy would probably be by using: https://docs.djangoproject.com/en/3.0/ref/settings/#std:setting-USE_X_FORWARDED_HOST

since that might be hard to some or they have no access to the reverse proxy config, i added a url param to the view which takes precedence over url_name. note however that schema versioning will not work there anymore. it's a compromise.

SpectacularSwaggerView.as_view(url='/api/schema/')

@tfranzel
Copy link
Owner

closing as this should be resolved. reopen if issue persists

@luisgc93
Copy link
Author

Yeah, sorry I didn't follow up. The issue seems to have been fixed.

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

2 participants