Connexion: HTTPD mod_wsgi aliases

Created on 20 Jan 2017  路  5Comments  路  Source: zalando/connexion

Description

When using connexion with httpd and mod_wsgi aliases the swagger.json URL is not being generated correctly.

In order to have more than one mod_wsgi script running on a single httpd instance aliases are used. For example...

_WSGIScriptAlias /myalias /path/to/my/mod_wsgi/script.wsgi_

So the URL for this mod_wsgi script would be...

_www.mydomain.com/myalias_

Now making the swagger base_path='/api' the ui URL would be...

_www.mydomain.com/myalias/api/ui_

This all works perfectly fine accept when the swagger.json url is generated. Connexion does not know anything about the alias that is configured in the httpd.conf file and so it is not using it to generates the swagger.json URL so the URL ends up looking like this...

_www.mydomain.com/api/swagger.json_

which is not correct. In this case it should be...

_www.mydomain.com/myalias/api/swagger.json_

If you manually set the swagger.json path correctly in the base_url input field things will work fine.

Everything also works fine when you set the WSGIScript Alias to something like this...

_WSGIScriptAlias / /path/to/my/mod_wsgi/script.wsgi_

This is effectively like not having an alias, However in many situations this is not possible as you can only set one of these blank alias per httpd virtual host.

I have been reading through the connexion source but have not come up with a good fix for this yet.

bug in progress

Most helpful comment

@Majoros would you be willing to do a PR with the fix? Thanks!

All 5 comments

I see the problem. I think the issue is with this line in swagger_ui_index: https://github.com/zalando/connexion/blob/master/connexion/api.py#L309

self.base_url does not know about your alias, but it's used as a template variable for Swagger UI index.html to point to swagger.json.

I think the function swagger_ui_index could either use the request's Host header or we simply use a relative path to point to swagger.json in index.html. Feel free to do a PR.

I finally had a some time to look into this. using the "flask.request.url_root" variable in the swagger_ui_index function works perfectly. unfortunately the url's generated by the "Try Out" buttons on the swagger UI page are still missing the alias. currently looking into why.

@Majoros would you be willing to do a PR with the fix? Thanks!

Absolutely, as soon as I figure-out a good solution.

Please take a look at #823 as it aims to solve this problem.
It includes and example for both Flask and AioHttp

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FRNCSCM picture FRNCSCM  路  4Comments

rudyces picture rudyces  路  3Comments

zd0 picture zd0  路  4Comments

trickidicki picture trickidicki  路  5Comments

writeson picture writeson  路  4Comments