Add support for multiple cors origins
This commit is contained in:
parent
08109dafbd
commit
413b27a21e
@ -3,5 +3,5 @@
|
|||||||
"apiLogPath": null,
|
"apiLogPath": null,
|
||||||
"webBindAddress": "127.0.0.1",
|
"webBindAddress": "127.0.0.1",
|
||||||
"webBindPort": 8765,
|
"webBindPort": 8765,
|
||||||
"webCorsOrigin": "http://localhost"
|
"webCorsOrigin": ["http://localhost"]
|
||||||
}
|
}
|
||||||
|
@ -153,10 +153,20 @@ class WebServer:
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
body = json.dumps(None).encode('utf-8')
|
body = json.dumps(None).encode('utf-8')
|
||||||
|
|
||||||
|
# handle multiple cors origins by checking the 'origin'-header against the allowed origin list from the config
|
||||||
|
webCorsOriginsSetting = util.setting('webCorsOrigin')
|
||||||
|
corsOrigin = "http://localhost"
|
||||||
|
if len(webCorsOriginsSetting) == 1:
|
||||||
|
corsOrigin = webCorsOriginsSetting[0]
|
||||||
|
elif b"origin" in req.headers:
|
||||||
|
originStr = req.headers[b"origin"].decode()
|
||||||
|
if originStr in webCorsOriginsSetting:
|
||||||
|
corsOrigin = originStr
|
||||||
|
|
||||||
headers = [
|
headers = [
|
||||||
['HTTP/1.1 200 OK', None],
|
['HTTP/1.1 200 OK', None],
|
||||||
['Content-Type', 'text/json'],
|
['Content-Type', 'text/json'],
|
||||||
['Access-Control-Allow-Origin', util.setting('webCorsOrigin')],
|
['Access-Control-Allow-Origin', corsOrigin],
|
||||||
['Content-Length', str(len(body))]
|
['Content-Length', str(len(body))]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user