From 8af6c65c9b7467e316e2d04f8cbcf34e73319a66 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Sun, 9 Feb 2020 04:16:15 -0600 Subject: [PATCH] api: Add support for necessary CORS headers. --- api/src/main/nim/personal_measure_apipkg/api.nim | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/api/src/main/nim/personal_measure_apipkg/api.nim b/api/src/main/nim/personal_measure_apipkg/api.nim index 55737a2..a484c7d 100644 --- a/api/src/main/nim/personal_measure_apipkg/api.nim +++ b/api/src/main/nim/personal_measure_apipkg/api.nim @@ -20,7 +20,7 @@ proc newSession*(user: User): Session = template halt(code: HttpCode, headers: RawHeaders, - content: string): typed = + content: string) = ## Immediately replies with the specified request. This means any further ## code will not be executed after calling this template in the current ## route. @@ -43,7 +43,8 @@ template jsonResp(code: HttpCode, body: string = "", headersToSend: RawHeaders = @{ "Access-Control-Allow-Origin": reqOrigin, "Access-Control-Allow-Credentials": "true", - "Access-Control-Allow-Methods": $(request.reqMethod) + "Access-Control-Allow-Methods": $(request.reqMethod), + "Access-Control-Allow-Headers": "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization" } else: @{:} @@ -68,11 +69,6 @@ template statusResp(code: HttpCode, details: string = "", headersToSend: RawHead }), headersToSend) -template execptionResp(ex: ref Exception, details: string = ""): void = - when not defined(release): debug ex.getStackTrace() - error details & ":\n" & ex.msg - statusResp(Http500) - # internal JSON parsing utils proc getIfExists(n: JsonNode, key: string): JsonNode = ## convenience method to get a key from a JObject or return null