Adds handling for GET / and GET /api
This commit is contained in:
parent
1b144e1248
commit
add109e51c
2 changed files with 14 additions and 2 deletions
|
@ -10,7 +10,7 @@ from aiohttp import web
|
||||||
|
|
||||||
import schema.db_helpers
|
import schema.db_helpers
|
||||||
from src.database import obtain_connection, DatabaseWriter
|
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__)
|
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(cleanup_background_tasks)
|
||||||
app.on_shutdown.append(close_comment_scheduler)
|
app.on_shutdown.append(close_comment_scheduler)
|
||||||
aiojobs.aiohttp.setup(app, **kwargs)
|
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
|
return app
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -122,3 +122,11 @@ async def api_endpoint(request: web.Request):
|
||||||
logger.exception(f'Exception raised by request from {request.remote}: {e}')
|
logger.exception(f'Exception raised by request from {request.remote}: {e}')
|
||||||
logger.debug(f'Request headers: {request.headers}')
|
logger.debug(f'Request headers: {request.headers}')
|
||||||
return make_error('INVALID_REQUEST', e)
|
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']
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in a new issue