-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraftmpd41_launch.py
56 lines (45 loc) · 1.89 KB
/
draftmpd41_launch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
portnum = 5610
print("Loading dependencies")
import tornado.ioloop
import tornado.web
from tornado import concurrent
from tornado import escape
import json, os, time, datetime
import pandas as pd
import uuid
import commonfuncs as cf
import dbconnect
import api1
cf.logmessage("All dependences loaded.")
root = os.path.dirname(__file__) # needed for tornado
# from https://stackoverflow.com/a/55762431/4355695 : restrict direct browser access to .py files and stuff
class MyStaticFileHandler(tornado.web.StaticFileHandler):
def set_extra_headers(self, path):
self.set_header("Cache-control", "no-cache") # https://stackoverflow.com/a/12031093/4355695
def validate_absolute_path(self, root, absolute_path):
page = os.path.basename(absolute_path)
# do blocking as necessary
# print(absolute_path, page)
if 'config' in absolute_path:
cf.logmessage('caught snooping!')
return os.path.join(root,'redirect.html')
return super().validate_absolute_path(root, absolute_path) # you may pass
class Application(tornado.web.Application):
_routes = [
# tornado.web.url(r"/API/fetchBreezoMap", api1.fetchBreezoMap),
tornado.web.url(r"/API/addInput", api1.addInput),
tornado.web.url(r"/API/listInputs", api1.listInputs),
tornado.web.url(r"/(.*)", MyStaticFileHandler, {"path": root, "default_filename": "redirect.html"})
]
def __init__(self):
settings = {
"debug": False, # make this false when pushing to openshift
"cookie_secret": "EYeRT%&)WERterGEfYTjR",
"compress_response": True # https://stackoverflow.com/a/11872086/4355695
}
super(Application, self).__init__(self._routes, **settings)
if __name__ == "__main__":
app = Application()
app.listen(port=portnum)
print(f"Launched on port {portnum}")
tornado.ioloop.IOLoop.current().start()