diff --git a/src/api_main.py b/src/api_main.py index 7fe9484c..bdb18cea 100644 --- a/src/api_main.py +++ b/src/api_main.py @@ -169,6 +169,11 @@ async def get_stats(request: web.Request, conn): "messages": message_count }) +@web.middleware +async def add_cors_headers(request, handler): + resp = await handler(request) + resp.headers["Access-Control-Allow-Origin"] = "*"; + return resp @web.middleware async def render_pk_errors(request, handler): @@ -178,7 +183,7 @@ async def render_pk_errors(request, handler): raise web.HTTPBadRequest(body=e.message) -app = web.Application(middlewares=[render_pk_errors]) +app = web.Application(middlewares=[render_pk_errors, add_cors_headers]) app.add_routes([ web.get("/systems/{id}", get_system), web.get("/systems/{id}/switches", get_switches),