From add109e51cfd371cc3400758508161b265353cfa Mon Sep 17 00:00:00 2001 From: Oleg Silkin Date: Mon, 22 Jul 2019 08:10:21 -0400 Subject: [PATCH] Adds handling for GET / and GET /api --- src/app.py | 8 ++++++-- src/handles.py | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/app.py b/src/app.py index 78da115..90404a9 100644 --- a/src/app.py +++ b/src/app.py @@ -10,7 +10,7 @@ from aiohttp import web import schema.db_helpers from src.database import obtain_connection, DatabaseWriter -from src.handles import api_endpoint +from src.handles import api_endpoint, get_api_endpoint logger = logging.getLogger(__name__) @@ -72,7 +72,11 @@ def create_app(conf, db_path='DEFAULT', **kwargs): app.on_shutdown.append(cleanup_background_tasks) app.on_shutdown.append(close_comment_scheduler) aiojobs.aiohttp.setup(app, **kwargs) - app.add_routes([web.post('/api', api_endpoint)]) + app.add_routes([ + web.post('/api', api_endpoint), + web.get('/', get_api_endpoint), + web.get('/api', get_api_endpoint) + ]) return app diff --git a/src/handles.py b/src/handles.py index 4652d9d..0a7bde2 100644 --- a/src/handles.py +++ b/src/handles.py @@ -122,3 +122,11 @@ async def api_endpoint(request: web.Request): logger.exception(f'Exception raised by request from {request.remote}: {e}') logger.debug(f'Request headers: {request.headers}') return make_error('INVALID_REQUEST', e) + + +async def get_api_endpoint(request: web.Request): + return web.json_response({ + 'text': 'OK', + 'is_running': True, + 'uptime': int(time.time()) - request.app['START_TIME'] + })