本文整理汇总了Python中werkzeug.middleware.dispatcher.DispatcherMiddleware方法的典型用法代码示例。如果您正苦于以下问题:Python dispatcher.DispatcherMiddleware方法的具体用法?Python dispatcher.DispatcherMiddleware怎么用?Python dispatcher.DispatcherMiddleware使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.middleware.dispatcher
的用法示例。
在下文中一共展示了dispatcher.DispatcherMiddleware方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_wsgi_middleware
# 需要导入模块: from werkzeug.middleware import dispatcher [as 别名]
# 或者: from werkzeug.middleware.dispatcher import DispatcherMiddleware [as 别名]
def init_wsgi_middleware(flask_app: Flask):
"""Handle X-Forwarded-* headers and base_url support"""
# Apply DispatcherMiddleware
base_url = urlparse(conf.get('webserver', 'base_url'))[2]
if not base_url or base_url == '/':
base_url = ""
if base_url:
flask_app.wsgi_app = DispatcherMiddleware( # type: ignore
_root_app, mounts={base_url: flask_app.wsgi_app}
)
# Apply ProxyFix middleware
if conf.getboolean('webserver', 'ENABLE_PROXY_FIX'):
flask_app.wsgi_app = ProxyFix( # type: ignore
flask_app.wsgi_app,
x_for=conf.getint("webserver", "PROXY_FIX_X_FOR", fallback=1),
x_proto=conf.getint("webserver", "PROXY_FIX_X_PROTO", fallback=1),
x_host=conf.getint("webserver", "PROXY_FIX_X_HOST", fallback=1),
x_port=conf.getint("webserver", "PROXY_FIX_X_PORT", fallback=1),
x_prefix=conf.getint("webserver", "PROXY_FIX_X_PREFIX", fallback=1),
)
示例2: setup_app
# 需要导入模块: from werkzeug.middleware import dispatcher [as 别名]
# 或者: from werkzeug.middleware.dispatcher import DispatcherMiddleware [as 别名]
def setup_app():
root_app = flask.Flask('cloudkitty')
root_api = flask_restful.Api(root_app)
root_api.add_resource(api_root.CloudkittyAPIRoot, '/')
dispatch_dict = {
'/v1': get_v1_app(),
'/v2': get_v2_app(),
}
# Disabling v2 api in case v1 storage is used
if CONF.storage.version < 2:
LOG.warning('v1 storage is used, disabling v2 API')
dispatch_dict.pop('/v2')
app = dispatcher.DispatcherMiddleware(root_app, dispatch_dict)
return app
示例3: _add_promethueus_middleware
# 需要导入模块: from werkzeug.middleware import dispatcher [as 别名]
# 或者: from werkzeug.middleware.dispatcher import DispatcherMiddleware [as 别名]
def _add_promethueus_middleware(app):
# Add prometheus wsgi middleware to route /metrics requests
# application object is then used by wsgi / gunicorn to startup the application
# NOTE: This means prometheus metrics are not exposed in development mode
wsgi_app = DispatcherMiddleware(app, {
'/metrics': make_wsgi_app()
})
return wsgi_app
示例4: main
# 需要导入模块: from werkzeug.middleware import dispatcher [as 别名]
# 或者: from werkzeug.middleware.dispatcher import DispatcherMiddleware [as 别名]
def main(
filenames, port, host, prefix, incognito, debug, profile, profile_dir
): # pragma: no cover
"""Start Fava for FILENAMES on http://<host>:<port>.
If the `BEANCOUNT_FILE` environment variable is set, Fava will use the
files (space-delimited) specified there in addition to FILENAMES.
Note you can also specify command-line options via environment variables.
For example, `--host=0.0.0.0` is equivalent to setting the environment
variable `FAVA_HOST=0.0.0.0`.
"""
if profile:
debug = True
env_filename = os.environ.get("BEANCOUNT_FILE")
if env_filename:
filenames = filenames + tuple(env_filename.split())
if not filenames:
raise click.UsageError("No file specified")
app.config["BEANCOUNT_FILES"] = filenames
app.config["INCOGNITO"] = incognito
if prefix:
app.wsgi_app = DispatcherMiddleware(
simple_wsgi, {prefix: app.wsgi_app}
)
if not debug:
server = Server((host, port), app)
print(f"Running Fava on http://{host}:{port}")
server.safe_start()
else:
if profile:
app.config["PROFILE"] = True
app.wsgi_app = ProfilerMiddleware(
app.wsgi_app,
restrictions=(30,),
profile_dir=profile_dir if profile_dir else None,
)
app.jinja_env.auto_reload = True
try:
app.run(host, port, debug)
except OSError as error:
if error.errno == errno.EADDRINUSE:
raise click.UsageError(
"Can not start webserver because the port is already in "
"use. Please choose another port with the '-p' option."
)
raise
# needed for pyinstaller: