11import logging as log
2+ import os
23
34from flask_restx import Api
45from flask_swagger_ui import get_swaggerui_blueprint
6+ from werkzeug .middleware .proxy_fix import ProxyFix
57
68api = Api (version = '1.0' , title = 'Python REST API' ,
79 description = 'Template for building Python REST APIs' )
@@ -15,16 +17,19 @@ def default_error_handler(_):
1517
1618
1719def init (app ):
18- # app.config['SERVER_NAME'] = server_name + ':' + str(cfg.get('port', 5000) )
20+ app .wsgi_app = ProxyFix ( app . wsgi_app )
1921 app .config ['SWAGGER_UI_DOC_EXPANSION' ] = 'list'
20- app .config ['RESTPLUS_VALIDATE ' ] = True
21- app .config ['RESTPLUS_MASK_SWAGGER ' ] = False
22+ app .config ['RESTX_VALIDATE ' ] = True
23+ app .config ['RESTX_MASK_SWAGGER ' ] = False
2224 app .config ['ERROR_404_HELP' ] = False
2325
24- api_root = ''
25- swagger_url = f"{ api_root } /api/docs" # URL for exposing Swagger UI (without trailing '/')
26+ server_name = os .environ .get ('BACKEND_API_URL' , None )
27+ if server_name is not None :
28+ app .config ['SERVER_NAME' ] = server_name
29+
30+ swagger_url = f"/docs" # URL for exposing Swagger UI (without trailing '/')
2631 log .debug ("Registering swagger ui: {}" .format (swagger_url ))
27- api_url = f"{ api_root } /swagger.json" # Our API url (can of course be a local resource)
32+ api_url = f"/swagger.json" # Our API url (can of course be a local resource)
2833 log .debug ("Registering swagger api: %s" , api_url )
2934
3035 # Call factory function to create our blueprint
0 commit comments