Fixed CORS support.
h3rald h3rald@h3rald.com
Sun, 18 Nov 2018 11:12:43 +0100
1 files changed,
5 insertions(+),
10 deletions(-)
jump to
M
src/litestorepkg/lib/utils.nim
→
src/litestorepkg/lib/utils.nim
@@ -20,23 +20,18 @@ proc setOrigin*(LS: LiteStore, req: LSRequest, headers: var HttpHeaders) =
var host = "" var port = "" var protocol = "http" - if req.url.hostname != "" and req.url.port != "": + headers["Vary"] = "Origin" + if req.headers.hasKey("Origin"): + headers["Access-Control-Allow-Origin"] = req.headers["Origin"] + return + elif req.url.hostname != "" and req.url.port != "": host = req.url.hostname port = req.url.port - elif req.headers.hasKey("Host"): - var parts = req.headers["Host"].split(":") - if (parts.len >= 2): - host = parts[0] - port = parts[1] - else: - host = parts[0] - port = "80" else: headers["Access-Control-Allow-Origin"] = "*" return if req.url.scheme != "": protocol = req.url.scheme - headers["Vary"] = "Origin" headers["Access-Control-Allow-Origin"] = "$1://$2:$3" % [protocol, host, port] proc isFolder*(id: string): bool =