def get_application(): path_map = { get_hashi_base_path(): hashi_view, get_zip_content_base_path(): zip_content_view, } return wsgi.PathInfoDispatcher(path_map)
def main() -> None: args = parse_arguments() if args.print_version: print('{}, version {}'.format(os.path.basename(sys.argv[0]), __version__)) sys.exit(0) elif args.print_default_config: Config.write_default_config(sys.stdout) sys.exit(0) config.read_config(args.config_filename) app = setup_app() if config.debug: if config.server_prefix != '/': app = DispatcherMiddleware( Flask('debugging_frontend'), {config.server_prefix: app}) # type: ignore run_simple(config.socket_host, config.socket_port, app, use_debugger=True, use_reloader=True) # type: ignore else: wsgi_server = wsgi.Server( (config.socket_host, config.socket_port), wsgi.PathInfoDispatcher({config.server_prefix: app})) wsgi_server.safe_start()
def run_webapp(self): from main.wsgi import application class Root(): pass cherrypy.config.update({'environment': 'production'}) static_app = cherrypy.tree.mount(Root(), '/', config={ '/': { 'tools.staticdir.on': True, 'tools.staticdir.dir': join(settings.ROOT_DIR, 'public') } }) addr = ('0.0.0.0', settings.HTTP_PLATFORM_PORT) dispatcher = wsgi.PathInfoDispatcher({ '/': application, '/static': static_app, }) server = wsgi.Server(addr, dispatcher) self.logger.info('Starting webapp: {}'.format(server._bind_addr)) server.safe_start()
def run(app, root_prefix="", hostname="0.0.0.0", http_port=None, https_port=None, https_cert_path=None, https_certkey_path=None): root_prefix = root_prefix or "" dispatcher = wsgi.PathInfoDispatcher({root_prefix: app}) global _http_server global _https_server http_thread = None https_thread = None if http_port: _http_server = wsgi.Server((hostname, http_port), dispatcher) http_thread = threading.Thread(target=_http_server.start) if https_port: _https_server = wsgi.Server((hostname, https_port), dispatcher) _https_server.ssl_adapter = BuiltinSSLAdapter(https_cert_path, https_certkey_path) https_thread = threading.Thread(target=_https_server.start) if http_thread is not None: http_thread.start() if https_thread is not None: https_thread.start()
def run_webapp(self): from main.wsgi import application class Root: pass cherrypy.config.update({"environment": "production"}) static_app = cherrypy.tree.mount( Root(), "/", config={ "/": { "tools.staticdir.on": True, "tools.staticdir.dir": join(settings.ROOT_DIR, "public"), } }, ) addr = ("0.0.0.0", settings.HTTP_PLATFORM_PORT) dispatcher = wsgi.PathInfoDispatcher({ "/": application, "/static": static_app }) server = wsgi.Server(addr, dispatcher) self.logger.info("Starting webapp: {}".format(server._bind_addr)) server.safe_start()
def _run_produc(self): bind_path = self.prefix.strip("/") + "/" bind_addr = (self.host, self.port) wsgi_app = wsgi.PathInfoDispatcher({bind_path: self.app}) server = wsgi.Server(bind_addr, wsgi_app) if self.use_ssl: server.ssl_adapter = BuiltinSSLAdapter(self.certfile, self.keyfile, self.certchain) #: hack cheroot to use our custom logger server.error_log = lambda *args, **kwgs: self.log.log( kwgs.get("level", logging.ERROR), args[0], exc_info=self.pyload.debug ) server.safe_start()
def get_server(config: Dict[str, Any]) -> wsgi.Server: bind_addr = (config["host"], config["port"]) server = _servers.get(bind_addr) if not server: dav_app = WsgiDAVApp(config) path_map = { "/test": partial(serve_document, config), "/dav": dav_app, } dispatch = wsgi.PathInfoDispatcher(path_map) server_args = { "bind_addr": bind_addr, "wsgi_app": dispatch, } server = wsgi.Server(**server_args) server.prepare() _servers[bind_addr] = server server._manabi_id = bind_addr return server
def main(): server_type = "werkzeug" if not config.debug_mode: server_type = "cherrypy" if config.web_server_type: server_type = config.web_server_type assert server_type in ("werkzeug", "cherrypy"), "Only werkzeug and cherrypy supported" if server_type == "werkzeug": assert config.debug_mode, "Refusing to use werkzeug outside of debug mode" app.run(config.web_host, config.web_port, debug=True, use_reloader=False, use_debugger=True, threaded=True) elif server_type == "cherrypy": dispatcher = wsgi.PathInfoDispatcher({"/": app}) web_server = wsgi.Server((config.web_host, config.web_port), dispatcher, server_name=config.web_public_host) web_server.start()
def configure_http_server(port): # Mount the application from kolibri.deployment.default.wsgi import application whitenoise_settings = { "static_root": settings.STATIC_ROOT, "static_prefix": settings.STATIC_URL, # Use 1 day as the default cache time for static assets "max_age": 24 * 60 * 60, # Add a test for any file name that contains a semantic version number # or a 32 digit number (assumed to be a file hash) # these files will be cached indefinitely "immutable_file_test": r"((0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)|[a-f0-9]{32})", "autorefresh": getattr(settings, "DEVELOPER_MODE", False), } # Mount static files application = DjangoWhiteNoise(application, **whitenoise_settings) cherrypy.tree.graft(application, "/") # Mount media files cherrypy.tree.mount( cherrypy.tools.staticdir.handler(section="/", dir=settings.MEDIA_ROOT), settings.MEDIA_URL, ) # Mount content files CONTENT_ROOT = "/" + paths.get_content_url( conf.OPTIONS["Deployment"]["URL_PATH_PREFIX"]).lstrip("/") content_dirs = [paths.get_content_dir_path() ] + paths.get_content_fallback_paths() dispatcher = MultiStaticDispatcher(content_dirs) content_handler = cherrypy.tree.mount( None, CONTENT_ROOT, config={ "/": { "tools.caching.on": False, "request.dispatch": dispatcher } }, ) cherrypy_server_config = { "server.socket_host": LISTEN_ADDRESS, "server.socket_port": port, "server.thread_pool": conf.OPTIONS["Server"]["CHERRYPY_THREAD_POOL"], "server.socket_timeout": conf.OPTIONS["Server"]["CHERRYPY_SOCKET_TIMEOUT"], "server.accepted_queue_size": conf.OPTIONS["Server"]["CHERRYPY_QUEUE_SIZE"], "server.accepted_queue_timeout": conf.OPTIONS["Server"]["CHERRYPY_QUEUE_TIMEOUT"], } # Configure the server cherrypy.config.update(cherrypy_server_config) alt_port_addr = ( LISTEN_ADDRESS, conf.OPTIONS["Deployment"]["ZIP_CONTENT_PORT"], ) # Mount static files alt_port_app = wsgi.PathInfoDispatcher({ "/": get_application(), CONTENT_ROOT: content_handler }) alt_port_app = DjangoWhiteNoise(alt_port_app, **whitenoise_settings) alt_port_server = ServerAdapter( cherrypy.engine, wsgi.Server( alt_port_addr, alt_port_app, numthreads=conf.OPTIONS["Server"]["CHERRYPY_THREAD_POOL"], request_queue_size=conf.OPTIONS["Server"]["CHERRYPY_QUEUE_SIZE"], timeout=conf.OPTIONS["Server"]["CHERRYPY_SOCKET_TIMEOUT"], accepted_queue_size=conf.OPTIONS["Server"]["CHERRYPY_QUEUE_SIZE"], accepted_queue_timeout=conf.OPTIONS["Server"] ["CHERRYPY_QUEUE_TIMEOUT"], ), alt_port_addr, ) # Subscribe these servers cherrypy.server.subscribe() alt_port_server.subscribe()
if mirror: db_session.delete(mirror) db_session.commit() return Response("Mirror '{}' removed.\n".format(identifier), 200, mimetype="text/plain") else: return Response("Mirror '{}' not found.\n".format(identifier), 404, mimetype="text/plain") @app.teardown_appcontext def shutdown_session(exception=None): if exception: LOGGER.warning("Shutdown Exception: %s", exception) db_session.remove() if __name__ == "__main__": redirect_app = Flask("redirect") @redirect_app.route("/") def default(): return redirect("/packagecontrol/", code=301) from cheroot import wsgi d = wsgi.PathInfoDispatcher({"/": redirect_app, "/packagecontrol": app}) server = wsgi.Server(("::", 9001), d) server.start()
from cheroot import wsgi from dwa import app if __name__ == "__main__": path_map = {'/': app} address = "127.0.0.1", 8000 disp = wsgi.PathInfoDispatcher(path_map) server = wsgi.Server(address, disp) server.start()