forked from odoo/owl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
46 lines (36 loc) · 1.41 KB
/
server.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
#!/usr/bin/env python3
import threading
import time
from http.server import SimpleHTTPRequestHandler, HTTPServer
HOST = '127.0.0.1'
PORT = 8000
URL = 'http://{0}:{1}/tools'.format(HOST, PORT)
# We define our own handler here to remap owl.js GET requests to the Owl build
# in dist/. This is useful for the benchmarks and playground applications.
# With this, we can simply copy the playground folder as is in the gh-page when
# we want to update the playground.
class OWLHandler(SimpleHTTPRequestHandler):
def do_GET(self):
if self.path == '/tools/owl.js':
self.path = '/dist/owl.iife.js'
return SimpleHTTPRequestHandler.do_GET(self)
def end_headers(self):
self.disable_cache_headers()
SimpleHTTPRequestHandler.end_headers(self)
def disable_cache_headers(self):
self.send_header("Cache-Control", "no-cache, no-store, must-revalidate")
self.send_header("Pragma", "no-cache")
self.send_header("Expires", "0")
OWLHandler.extensions_map['.js'] = 'application/javascript'
if __name__ == "__main__":
print("Owl Tools")
print("---------")
print("Server running on: {}".format(URL))
httpd = HTTPServer((HOST, PORT), OWLHandler)
threading.Thread(target=httpd.serve_forever, daemon=True).start()
while True:
try:
time.sleep(1)
except KeyboardInterrupt:
httpd.server_close()
quit(0)