Add support for use '*' to allow CORS for all domains

This commit is contained in:
yekingyan 2020-04-12 15:52:52 +08:00
parent 0bba096775
commit e0e0e57321

View File

@ -162,11 +162,12 @@ class WebServer:
webCorsOriginList.append(webCorsOrigin)
corsOrigin = 'http://localhost'
if len(webCorsOriginList) == 1:
allowAllCors = '*' in webCorsOriginList # allow CORS for all domains
if len(webCorsOriginList) == 1 and not allowAllCors:
corsOrigin = webCorsOriginList[0]
elif b'origin' in req.headers:
originStr = req.headers[b'origin'].decode()
if originStr in webCorsOriginList:
if originStr in webCorsOriginList or allowAllCors:
corsOrigin = originStr
headers = [