all repos — litestore @ dbc4c7deba145947bc2a7cc846c4ba9f2e9bed2f

A minimalist nosql document store.

Fixed CORS support.
h3rald h3rald@h3rald.com
Sun, 18 Nov 2018 11:12:43 +0100
commit

dbc4c7deba145947bc2a7cc846c4ba9f2e9bed2f

parent

2536597f991f39e90f7bd7851e2bc8df6885f492

1 files changed, 5 insertions(+), 10 deletions(-)

jump to
M src/litestorepkg/lib/utils.nimsrc/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 =