def start_server():
"""
Initialize and start the server.
"""
if hasattr(cherrypy.engine, 'subscribe'): # CherryPy >= 3.1
pass
else:
raise Exception("This application requires CherryPy >= 3.1 or higher.")
# cherrypy.engine.on_stop_engine_list.append(_save_data)
# Some global configuration
cherrypy.config.update({"server.ssl_certificate": os.path.join(os.path.dirname(__file__), "../cert.pem"),
"server.ssl_private_key": os.path.join(os.path.dirname(__file__), "../privkey.pem")})
# cherrypy.config.update(config=os.path.join(script_dir, "config.ini"))
app = cherrypy.tree.mount(Server(), '/',
{'/':
{
"tools.staticdir.root": os.path.abspath(
os.path.join(os.path.dirname(__file__), "static")),
"tools.decode.on": True,
"tools.trailing_slash.on": True,
"tools.staticdir.on": True,
"tools.staticdir.index": "index.html",
"tools.staticdir.dir": ""
}
})
if hasattr(cherrypy.engine, "signal_handler"):
cherrypy.engine.signal_handler.subscribe()
if hasattr(cherrypy.engine, "console_control_handler"):
cherrypy.engine.console_control_handler.subscribe()
cherrypy.engine.start()
cherrypy.engine.block()
评论列表
文章目录