CORS in dev_server.
This commit is contained in:
parent
581af133ea
commit
50f0b64182
|
@ -15,34 +15,46 @@ routes = web.RouteTableDef()
|
||||||
|
|
||||||
@routes.get("/{tail:.*}")
|
@routes.get("/{tail:.*}")
|
||||||
async def get_handler(request: web.Request) -> web.Response:
|
async def get_handler(request: web.Request) -> web.Response:
|
||||||
data = await request.get()
|
alog.info("GET -> [%s]: %s", request.path, request.query)
|
||||||
alog.info("GET -> [%s]: %s", request.path, data)
|
return web.json_response(
|
||||||
return web.json_response({"method": request.method, "path": request.path})
|
{"method": request.method, "path": request.path},
|
||||||
|
headers={"Access-Control-Allow-Origin": "*"},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@routes.post("/{tail:.*}")
|
@routes.post("/{tail:.*}")
|
||||||
async def post_handler(request: web.Request) -> web.Response:
|
async def post_handler(request: web.Request) -> web.Response:
|
||||||
data = await request.post()
|
data = await request.post()
|
||||||
alog.info("POST -> [%s]: %s", request.path, data)
|
alog.info("POST -> [%s]: %s", request.path, data)
|
||||||
return web.json_response({"method": request.method, "path": request.path})
|
return web.json_response(
|
||||||
|
{"method": request.method, "path": request.path},
|
||||||
|
headers={"Access-Control-Allow-Origin": "*"},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@routes.put("/{tail:.*}")
|
@routes.put("/{tail:.*}")
|
||||||
async def put_handler(request: web.Request) -> web.Response:
|
async def put_handler(request: web.Request) -> web.Response:
|
||||||
data = await request.put()
|
data = await request.post()
|
||||||
alog.info("PUT -> [%s]: %s", request.path, data)
|
alog.info("PUT -> [%s]: %s", request.path, data)
|
||||||
return web.json_response({"method": request.method, "path": request.path})
|
return web.json_response(
|
||||||
|
{"method": request.method, "path": request.path},
|
||||||
|
headers={"Access-Control-Allow-Origin": "*"},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@routes.delete("/{tail:.*}")
|
@routes.delete("/{tail:.*}")
|
||||||
async def delete_handler(request: web.Request) -> web.Response:
|
async def delete_handler(request: web.Request) -> web.Response:
|
||||||
alog.info("DELETE -> [%s]", request.path)
|
data = await request.post()
|
||||||
return web.json_response({"method": request.method, "path": request.path})
|
alog.info("DELETE -> [%s]: %s", request.path, data)
|
||||||
|
return web.json_response(
|
||||||
|
{"method": request.method, "path": request.path},
|
||||||
|
headers={"Access-Control-Allow-Origin": "*"},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def options_handler(request: web.Request) -> web.Response:
|
async def options_handler(request: web.Request) -> web.Response:
|
||||||
alog.info("OPTIONS -> [%s]", request.path)
|
alog.info("OPTIONS -> [%s]", request.path)
|
||||||
return web.Response(status=200, headers={"Access-Control-Allow-Origin": "*"})
|
return web.Response(status=200)
|
||||||
|
|
||||||
|
|
||||||
def run(address: str, port: int) -> None:
|
def run(address: str, port: int) -> None:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user