Serve dashb0ard and static content on startup
This commit is contained in:
parent
65d2715ea5
commit
d147a81499
1 changed files with 20 additions and 2 deletions
|
@ -8,14 +8,24 @@ import re
|
|||
import pwd
|
||||
import platform
|
||||
from subprocess import Popen, PIPE
|
||||
from _thread import start_new_thread
|
||||
|
||||
from wsgiref.simple_server import make_server
|
||||
from ws4py.server.wsgirefserver import WSGIServer, WebSocketWSGIRequestHandler
|
||||
from ws4py.server.wsgiutils import WebSocketWSGIApplication
|
||||
|
||||
import behem0th
|
||||
from bottle.bottle import route, run, static_file
|
||||
|
||||
|
||||
@route("/")
|
||||
def index():
|
||||
return static_file("index.html", root="Shared/dashb1ard")
|
||||
|
||||
@route("/static/<filepath:path>")
|
||||
def static(filepath):
|
||||
return static_file(filepath, root="Shared/dashb1ard/static")
|
||||
|
||||
class Info(Route):
|
||||
def run(self, data, handler):
|
||||
handler.send({"routes" : list(handler.routes.keys())}, "info")
|
||||
|
@ -195,7 +205,9 @@ CONFIG_PATH = "server.cfg"
|
|||
|
||||
|
||||
config = Config()
|
||||
config.add(Option("server_address", ("127.0.0.1", 3077)))
|
||||
config.add(Option("fl0w_address", ("127.0.0.1", 3077)))
|
||||
config.add(Option("behem0th_address", ("127.0.0.1", 3078)))
|
||||
config.add(Option("dashb0ard_address", ("127.0.0.1", 8080)))
|
||||
config.add(Option("debug", True, validator=lambda x: True if True or False else False))
|
||||
config.add(Option("path", "Content", validator=folder_validator))
|
||||
|
||||
|
@ -209,7 +221,7 @@ except (IOError, ExceptionInConfigError):
|
|||
#compile = Compile(config.source_path, config.binary_path)
|
||||
|
||||
|
||||
server = make_server(config.server_address[0], config.server_address[1],
|
||||
server = make_server(config.fl0w_address[0], config.fl0w_address[1],
|
||||
server_class=WSGIServer, handler_class=WebSocketWSGIRequestHandler,
|
||||
app=None)
|
||||
server.initialize_websockets_manager()
|
||||
|
@ -239,6 +251,12 @@ sync_client = behem0th.Client(path=config.path, verbose_log=config.debug)
|
|||
try:
|
||||
Logging.header("Server loop starting.")
|
||||
sync_client.listen()
|
||||
start_new_thread(run, (), {"host" : config.dashb0ard_address[0],
|
||||
"port" : config.dashb0ard_address[1], "quiet" : True})
|
||||
Logging.info("Starting dashb0ard on 'http://%s:%d'" % (config.dashb0ard_address[0],
|
||||
config.dashb0ard_address[1]))
|
||||
Logging.info("Starting fl0w on 'ws://%s:%d'" % (config.fl0w_address[0],
|
||||
config.fl0w_address[1]))
|
||||
server.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
Logging.header("Gracefully shutting down server.")
|
||||
|
|
Reference in a new issue