Skip to content

Commit

Permalink
Fix: CORS did not work
Browse files Browse the repository at this point in the history
  • Loading branch information
hoh committed Jan 26, 2024
1 parent 445a678 commit 3f97bf6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
4 changes: 1 addition & 3 deletions src/aleph/vm/orchestrator/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ async def about_system_usage(_: web.Request):
),
properties=get_machine_properties(),
)
return web.json_response(
text=usage.json(exclude_none=True),
)
return web.json_response(text=usage.json(exclude_none=True), headers={"Access-Control-Allow-Origin:": "*"})


class Allocation(BaseModel):
Expand Down
21 changes: 13 additions & 8 deletions src/aleph/vm/orchestrator/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ async def list_executions(request: web.Request) -> web.Response:
if execution.is_running
},
dumps=dumps_for_json,
headers={"Access-Control-Allow-Origin": "*"},
)


Expand All @@ -156,10 +157,7 @@ async def about_config(request: web.Request) -> web.Response:

async def about_execution_records(_: web.Request):
records = await get_execution_records()
return web.json_response(
records,
dumps=dumps_for_json,
)
return web.json_response(records, dumps=dumps_for_json, headers={"Access-Control-Allow-Origin": "*"})


async def index(request: web.Request):
Expand Down Expand Up @@ -199,7 +197,9 @@ async def status_check_fastapi(request: web.Request):
# "ipv6": await status.check_ipv6(session),
}

return web.json_response(result, status=200 if all(result.values()) else 503)
return web.json_response(
result, status=200 if all(result.values()) else 503, headers={"Access-Control-Allow-Origin": "*"}
)


async def status_check_host(request: web.Request):
Expand All @@ -218,7 +218,7 @@ async def status_check_host(request: web.Request):
},
}
result_status = 200 if all(result["ipv4"].values()) and all(result["ipv6"].values()) else 503
return web.json_response(result, status=result_status)
return web.json_response(result, status=result_status, headers={"Access-Control-Allow-Origin": "*"})


async def status_check_ipv6(request: web.Request):
Expand All @@ -231,7 +231,7 @@ async def status_check_ipv6(request: web.Request):
vm_ipv6 = False

result = {"host": await check_host_egress_ipv6(), "vm": vm_ipv6}
return web.json_response(result, headers={"Access-Control-Allow-Origin:": "*"})
return web.json_response(result, headers={"Access-Control-Allow-Origin": "*"})


async def status_check_version(request: web.Request):
Expand All @@ -250,7 +250,11 @@ async def status_check_version(request: web.Request):
raise web.HTTPServiceUnavailable(text=error.args[0]) from error

if current >= reference:
return web.Response(status=200, text=f"Up-to-date: version {current} >= {reference}")
return web.Response(
status=200,
text=f"Up-to-date: version {current} >= {reference}",
headers={"Access-Control-Allow-Origin": "*"},
)
else:
return web.HTTPForbidden(text=f"Outdated: version {current} < {reference}")

Expand Down Expand Up @@ -292,6 +296,7 @@ async def status_public_config(request: web.Request):
},
},
dumps=dumps_for_json,
headers={"Access-Control-Allow-Origin": "*"},
)


Expand Down

0 comments on commit 3f97bf6

Please sign in to comment.