[CORD-1136] Added option to configure the swagger endpoint
Change-Id: I21b7a961bba5c133805a8ed63a4cb6fae57c5394
diff --git a/web_server/web_server.py b/web_server/web_server.py
index 433ed4d..b3f0385 100644
--- a/web_server/web_server.py
+++ b/web_server/web_server.py
@@ -37,11 +37,12 @@
app = Klein()
- def __init__(self, port, work_dir, grpc_client):
+ def __init__(self, port, work_dir, swagger_url, grpc_client):
self.port = port
self.site = None
self.work_dir = work_dir
self.grpc_client = grpc_client
+ self.swagger_url = swagger_url
self.swagger_ui_root_dir = os.path.abspath(
os.path.join(os.path.dirname(__file__), '../swagger_ui'))
@@ -49,6 +50,26 @@
self.tcp_port = None
self.shutting_down = False
+ self.add_swagger_routes(self.app, swagger_url)
+
+ def add_swagger_routes(self, app, swagger_url):
+ log.info('Publishing swagger docs at %s' % swagger_url)
+
+ @app.route(swagger_url + '/', branch=True)
+ def static(self, request):
+ try:
+ log.debug(request=request)
+ return File(self.swagger_ui_root_dir)
+ except Exception, e:
+ log.exception('file-not-found', request=request)
+
+ @app.route(swagger_url + '/v1/swagger.json')
+ def swagger_json(self, request):
+ try:
+ return File(os.path.join(self.work_dir, 'swagger.json'))
+ except Exception, e:
+ log.exception('file-not-found', request=request)
+
@inlineCallbacks
def start(self):
log.debug('starting')
@@ -82,25 +103,6 @@
m.add_routes(self.app, self.grpc_client)
log.info('routes-loaded', module=module_name)
- # static swagger_ui website as landing page (for now)
-
- @app.route('/', branch=True)
- def static(self, request):
- try:
- log.debug(request=request)
- return File(self.swagger_ui_root_dir)
- except Exception, e:
- log.exception('file-not-found', request=request)
-
- # static swagger.json file to serve the schema
-
- @app.route('/v1/swagger.json')
- def swagger_json(self, request):
- try:
- return File(os.path.join(self.work_dir, 'swagger.json'))
- except Exception, e:
- log.exception('file-not-found', request=request)
-
@app.handle_errors(grpc._channel._Rendezvous)
def grpc_exception(self, request, failure):
code = failure.value.code()