You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.4 KiB
50 lines
1.4 KiB
#tornado needs this or it does not run
|
|
import asyncio
|
|
try:
|
|
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
|
except AttributeError:
|
|
print("Probably running on linux")
|
|
|
|
from bottle import route, run, response, static_file, request, post
|
|
from .file_watchdog import FileWatchdog
|
|
|
|
|
|
class BottleServer:
|
|
|
|
def __init__(self, listen="0.0.0.0", port=8080, start_thread=True, root="web"):
|
|
|
|
self.root = root
|
|
|
|
self.port = port
|
|
self.listen = listen
|
|
self.wdt = FileWatchdog(self.root)
|
|
|
|
if start_thread:
|
|
import threading
|
|
self.thread = threading.Thread(target=self._run, args=())
|
|
self.thread.name = "BottleServerThread"
|
|
self.thread.daemon = True
|
|
self.thread.start()
|
|
else:
|
|
self._run()
|
|
|
|
def _home(self):
|
|
return static_file("index.html", root= self.root)
|
|
|
|
def _watchdog(self):
|
|
return str(self.wdt.time)
|
|
|
|
def _files(self, name):
|
|
if name.endswith(".vue"):
|
|
return static_file(name, root= self.root, mimetype="text/html")
|
|
return static_file(name, root= self.root)
|
|
|
|
def _run(self):
|
|
|
|
route('/')(self._home)
|
|
route('/watchdog')(self._watchdog)
|
|
route('/<name:path>')(self._files)
|
|
|
|
print(f"Starting server at {self.listen}:{self.port}")
|
|
run(host=self.listen, port=self.port, debug=False, threaded=True, quiet=True)
|
|
|
|
|