api: Add support for necessary CORS headers.
This commit is contained in:
parent
e14097117f
commit
8af6c65c9b
@ -20,7 +20,7 @@ proc newSession*(user: User): Session =
|
|||||||
|
|
||||||
template halt(code: HttpCode,
|
template halt(code: HttpCode,
|
||||||
headers: RawHeaders,
|
headers: RawHeaders,
|
||||||
content: string): typed =
|
content: string) =
|
||||||
## Immediately replies with the specified request. This means any further
|
## Immediately replies with the specified request. This means any further
|
||||||
## code will not be executed after calling this template in the current
|
## code will not be executed after calling this template in the current
|
||||||
## route.
|
## route.
|
||||||
@ -43,7 +43,8 @@ template jsonResp(code: HttpCode, body: string = "", headersToSend: RawHeaders =
|
|||||||
@{
|
@{
|
||||||
"Access-Control-Allow-Origin": reqOrigin,
|
"Access-Control-Allow-Origin": reqOrigin,
|
||||||
"Access-Control-Allow-Credentials": "true",
|
"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: @{:}
|
else: @{:}
|
||||||
|
|
||||||
@ -68,11 +69,6 @@ template statusResp(code: HttpCode, details: string = "", headersToSend: RawHead
|
|||||||
}),
|
}),
|
||||||
headersToSend)
|
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
|
# internal JSON parsing utils
|
||||||
proc getIfExists(n: JsonNode, key: string): JsonNode =
|
proc getIfExists(n: JsonNode, key: string): JsonNode =
|
||||||
## convenience method to get a key from a JObject or return null
|
## convenience method to get a key from a JObject or return null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user