[IMP] extras: update server to python3, disable cache

This commit is contained in:
Vincent Schippefilt
2019-06-03 14:27:45 +02:00
committed by Géry Debongnie
parent d22219f084
commit 5842ed51b0
3 changed files with 39 additions and 28 deletions
+18 -12
View File
@@ -39,26 +39,32 @@ const DEFAULT_HTML = `<!DOCTYPE html>
</html>
`;
const APP_PY = `import sys
import thread
import webbrowser
const APP_PY = `#!/usr/bin/env python3
import threading
import time
import BaseHTTPServer, SimpleHTTPServer
from http.server import SimpleHTTPRequestHandler, HTTPServer
def start_server():
httpd = BaseHTTPServer.HTTPServer(('127.0.0.1', 3600), SimpleHTTPServer.SimpleHTTPRequestHandler)
SimpleHTTPRequestHandler.extensions_map['.js'] = 'application/javascript'
httpd = HTTPServer(('0.0.0.0', 3600), SimpleHTTPRequestHandler)
httpd.serve_forever()
thread.start_new_thread(start_server,())
url = 'http://127.0.0.1:3600'
webbrowser.open_new(url)
while True:
try:
time.sleep(1)
except KeyboardInterrupt:
sys.exit(0)
if __name__ == "__main__":
print("Owl Application")
print("---------------")
print("Server running on: {}".format(url))
threading.Thread(target=start_server, daemon=True).start()
while True:
try:
time.sleep(1)
except KeyboardInterrupt:
httpd.server_close()
quit(0)
`;
/**
+20 -15
View File
@@ -1,10 +1,8 @@
import sys
import thread
import webbrowser
import time
#!/usr/bin/env python3
import BaseHTTPServer
import SimpleHTTPServer
import threading
import time
from http.server import SimpleHTTPRequestHandler, HTTPServer
HOST = '127.0.0.1'
PORT = 8000
@@ -15,27 +13,34 @@ URL = 'http://{0}:{1}/extras'.format(HOST, PORT)
# 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(SimpleHTTPServer.SimpleHTTPRequestHandler):
class OWLHandler(SimpleHTTPRequestHandler):
def do_GET(self):
if self.path == '/extras/owl.js':
self.path = '/dist/owl.js'
return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
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")
def start_server():
httpd = BaseHTTPServer.HTTPServer((HOST, PORT), OWLHandler)
httpd.serve_forever()
OWLHandler.extensions_map['.js'] = 'application/javascript'
if __name__ == "__main__":
print("Owl Extras")
print("----------")
print("Server running on: {}".format(URL))
thread.start_new_thread(start_server, ())
webbrowser.open_new(URL)
httpd = HTTPServer((HOST, PORT), OWLHandler)
threading.Thread(target=httpd.serve_forever, daemon=True).start()
while True:
try:
time.sleep(1)
except KeyboardInterrupt:
sys.exit(0)
httpd.server_close()
quit(0)
+1 -1
View File
@@ -10,7 +10,7 @@
"minify": "uglifyjs dist/owl.js -o dist/owl.min.js --compress --mangle",
"test": "jest",
"test:watch": "jest --watch",
"extras:serve": "python extras/server.py",
"extras:serve": "python3 extras/server.py || python extras/server.py",
"extras": "npm run build && npm run extras:serve",
"extras:watch": "npm-run-all --parallel extras:serve \"build:* -- --watch\""
},