2019-06-03 14:27:45 +02:00
|
|
|
#!/usr/bin/env python3
|
2019-04-29 22:54:26 +02:00
|
|
|
|
2019-06-03 14:27:45 +02:00
|
|
|
import threading
|
|
|
|
|
import time
|
|
|
|
|
from http.server import SimpleHTTPRequestHandler, HTTPServer
|
2019-05-03 11:14:34 +02:00
|
|
|
|
|
|
|
|
HOST = '127.0.0.1'
|
|
|
|
|
PORT = 8000
|
2019-06-09 16:56:27 +02:00
|
|
|
URL = 'http://{0}:{1}/tools'.format(HOST, PORT)
|
2019-05-03 11:14:34 +02:00
|
|
|
|
|
|
|
|
|
2019-05-03 16:38:24 +02:00
|
|
|
# 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.
|
2019-06-03 14:27:45 +02:00
|
|
|
class OWLHandler(SimpleHTTPRequestHandler):
|
2019-05-03 11:14:34 +02:00
|
|
|
def do_GET(self):
|
2019-06-09 16:56:27 +02:00
|
|
|
if self.path == '/tools/owl.js':
|
2019-05-03 11:14:34 +02:00
|
|
|
self.path = '/dist/owl.js'
|
2019-06-03 14:27:45 +02:00
|
|
|
return SimpleHTTPRequestHandler.do_GET(self)
|
|
|
|
|
|
|
|
|
|
def end_headers(self):
|
|
|
|
|
self.disable_cache_headers()
|
|
|
|
|
SimpleHTTPRequestHandler.end_headers(self)
|
2019-05-03 11:14:34 +02:00
|
|
|
|
2019-06-03 14:27:45 +02:00
|
|
|
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")
|
2019-04-29 22:54:26 +02:00
|
|
|
|
|
|
|
|
|
2019-06-03 14:27:45 +02:00
|
|
|
OWLHandler.extensions_map['.js'] = 'application/javascript'
|
2019-04-29 22:54:26 +02:00
|
|
|
|
2019-05-03 11:14:34 +02:00
|
|
|
if __name__ == "__main__":
|
2019-06-11 11:29:31 +02:00
|
|
|
print("Owl Tools")
|
|
|
|
|
print("---------")
|
2019-06-04 10:25:50 +02:00
|
|
|
print("Server running on: {}".format(URL))
|
2019-06-03 14:27:45 +02:00
|
|
|
httpd = HTTPServer((HOST, PORT), OWLHandler)
|
|
|
|
|
threading.Thread(target=httpd.serve_forever, daemon=True).start()
|
2019-05-03 11:14:34 +02:00
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
try:
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
except KeyboardInterrupt:
|
2019-06-03 14:27:45 +02:00
|
|
|
httpd.server_close()
|
|
|
|
|
quit(0)
|