Header for websocket connection on non-localhost

This commit is contained in:
Hugvey Central Command 2019-05-13 12:08:31 +02:00
parent b8b912a10a
commit 9a91f9f175

View file

@ -223,6 +223,11 @@ def getVoiceHandler(voiceStorage):
self.finish()
return VoiceHandler
class StaticFileWithHeaderHandler(tornado.web.StaticFileHandler):
def set_extra_headers(self, path):
"""For subclass to add extra headers to the response"""
if path[-5:] == '.html':
self.set_header("Access-Control-Allow-Origin", "*")
class Panopticon(object):
def __init__(self, central_command, config, voiceStorage):
@ -239,7 +244,7 @@ class Panopticon(object):
{"path": config['web']['files_dir']}),
(r"/upload", getUploadHandler(self.command)),
(r"/voice", getVoiceHandler(self.voiceStorage)),
(r"/(.*)", tornado.web.StaticFileHandler,
(r"/(.*)", StaticFileWithHeaderHandler,
{"path": web_dir, "default_filename": 'index.html'}),
], debug=True)
@ -278,4 +283,3 @@ class Panopticon(object):
j = json.dumps(msg)
logger.debug(j)
self.loop.add_callback(wsHandler.write_to_clients, j)