def run(self): """ While we could use the standard decorators to register these routes, using add_url_rule() allows us to create diffrent endpoint names programmatically and pass the classes self object to the routes """ config = Config() config.host = self['BindIP'] config.port = self['Port'] config.debug = False config.use_reloader = False http_blueprint = Blueprint(__name__, 'http') http_blueprint.before_request(self.check_if_naughty) #http_blueprint.after_request(self.make_normal) http_blueprint.add_url_rule('/<uuid:GUID>', 'key_exchange', self.key_exchange, methods=['POST']) http_blueprint.add_url_rule('/<uuid:GUID>', 'stage', self.stage, methods=['GET']) http_blueprint.add_url_rule('/<uuid:GUID>/jobs', 'jobs', self.jobs, methods=['GET']) http_blueprint.add_url_rule('/<uuid:GUID>/jobs/<job_id>', 'job_result', self.job_result, methods=['POST']) # Add a catch all route http_blueprint.add_url_rule('/', 'unknown_path', self.unknown_path, defaults={'path': ''}) http_blueprint.add_url_rule('/<path:path>', 'unknown_path', self.unknown_path, methods=['GET', 'POST']) #logging.getLogger('quart.app').setLevel(logging.DEBUG if state.args['--debug'] else logging.ERROR) #logging.getLogger('quart.serving').setLevel(logging.DEBUG if state.args['--debug'] else logging.ERROR) self.app = Quart(__name__) self.app.register_blueprint(http_blueprint) asyncio.run(serve(self.app, config))
def run_command(info: ScriptInfo, host: str, port: int) -> None: config = Config() config.access_log_format = "%(h)s %(r)s %(s)s %(b)s %(D)s" config.access_logger = create_serving_logger() config.debug = True config.error_logger = config.access_logger config.host = host config.port = port config.use_reloader = True run_single(info.load_app(), config)