Fix JS modules

This commit is contained in:
Ivanq 2019-05-05 22:05:58 +03:00
parent 5456f0e106
commit ed85981409

View file

@ -181,11 +181,11 @@ class UiRequest(object):
if file_name.endswith(".css"): # Force correct css content type
content_type = "text/css"
if not content_type:
if file_name.endswith(".js"): # Force correct javascript content type
content_type = "text/javascript"
if file_name.endswith(".json"): # Correct json header
content_type = "application/json"
else:
if not content_type:
content_type = "application/octet-stream"
return content_type
@ -251,6 +251,8 @@ class UiRequest(object):
headers["X-Frame-Options"] = "SAMEORIGIN"
if content_type != "text/html" and self.env.get("HTTP_REFERER") and self.isSameOrigin(self.getReferer(), self.getRequestUrl()):
headers["Access-Control-Allow-Origin"] = "*" # Allow load font files from css
if content_type == "text/javascript" and not self.env.get("HTTP_REFERER"):
headers["Access-Control-Allow-Origin"] = "*" # Allow loading JavaScript modules in Chrome
if noscript:
headers["Content-Security-Policy"] = "default-src 'none'; sandbox allow-top-navigation allow-forms; img-src 'self'; font-src 'self'; media-src 'self'; style-src 'self' 'unsafe-inline';"