CORS in dev_server.
This commit is contained in:
parent
581af133ea
commit
50f0b64182
|
@ -15,34 +15,46 @@ routes = web.RouteTableDef()
|
|||
|
||||
@routes.get("/{tail:.*}")
|
||||
async def get_handler(request: web.Request) -> web.Response:
|
||||
data = await request.get()
|
||||
alog.info("GET -> [%s]: %s", request.path, data)
|
||||
return web.json_response({"method": request.method, "path": request.path})
|
||||
alog.info("GET -> [%s]: %s", request.path, request.query)
|
||||
return web.json_response(
|
||||
{"method": request.method, "path": request.path},
|
||||
headers={"Access-Control-Allow-Origin": "*"},
|
||||
)
|
||||
|
||||
|
||||
@routes.post("/{tail:.*}")
|
||||
async def post_handler(request: web.Request) -> web.Response:
|
||||
data = await request.post()
|
||||
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:.*}")
|
||||
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)
|
||||
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:.*}")
|
||||
async def delete_handler(request: web.Request) -> web.Response:
|
||||
alog.info("DELETE -> [%s]", request.path)
|
||||
return web.json_response({"method": request.method, "path": request.path})
|
||||
data = await request.post()
|
||||
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:
|
||||
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:
|
||||
|
|
Loading…
Reference in New Issue
Block a user