1
1
import logging as log
2
+ import os
2
3
3
4
from flask_restx import Api
4
5
from flask_swagger_ui import get_swaggerui_blueprint
6
+ from werkzeug .middleware .proxy_fix import ProxyFix
5
7
6
8
api = Api (version = '1.0' , title = 'Python REST API' ,
7
9
description = 'Template for building Python REST APIs' )
@@ -15,16 +17,19 @@ def default_error_handler(_):
15
17
16
18
17
19
def init (app ):
18
- # app.config['SERVER_NAME'] = server_name + ':' + str(cfg.get('port', 5000) )
20
+ app .wsgi_app = ProxyFix ( app . wsgi_app )
19
21
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
22
24
app .config ['ERROR_404_HELP' ] = False
23
25
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 '/')
26
31
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)
28
33
log .debug ("Registering swagger api: %s" , api_url )
29
34
30
35
# Call factory function to create our blueprint
0 commit comments