Add CORS headers to API responses

This commit is contained in:
Ske 2019-02-28 17:22:26 +01:00
parent f174ce9a03
commit 6952de98cf

View File

@ -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),