Skip to content

Commit

Permalink
Add OPTIONS endpoint to allow the content-type header for the upload …
Browse files Browse the repository at this point in the history
…endpoint (#869)

* Add OPTIONS endpoint to allow the content-type header
exec git commit --amend --no-edit -S

* Remove useless header "Access-Control-Headers" and add cache

Signed-off-by: Arnaud <[email protected]>

---------

Signed-off-by: Arnaud <[email protected]>
Co-authored-by: Giuliano Mega <[email protected]>
  • Loading branch information
2-towns and gmega authored Aug 14, 2024
1 parent 2771ca6 commit bb9a5fb
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions codex/rest/api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ proc retrieveCid(
proc initDataApi(node: CodexNodeRef, repoStore: RepoStore, router: var RestRouter) =
let allowedOrigin = router.allowedOrigin # prevents capture inside of api defintion

router.api(
MethodOptions,
"/api/codex/v1/data") do (
resp: HttpResponseRef) -> RestApiResponse:

if corsOrigin =? allowedOrigin:
resp.setHeader("Access-Control-Allow-Origin", corsOrigin)
resp.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS")
resp.setHeader("Access-Control-Allow-Headers", "content-type")
resp.setHeader("Access-Control-Max-Age", "86400")

resp.status = Http204
await resp.sendBody("")

router.rawApi(
MethodPost,
"/api/codex/v1/data") do (
Expand Down

0 comments on commit bb9a5fb

Please sign in to comment.