diff --git a/codex/rest/api.nim b/codex/rest/api.nim index d44cffa4e..b209e7c9b 100644 --- a/codex/rest/api.nim +++ b/codex/rest/api.nim @@ -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 (