当前位置: 首页>>代码示例>>Python>>正文


Python dispatcher.DispatcherMiddleware方法代码示例

本文整理汇总了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),
        ) 
开发者ID:apache,项目名称:airflow,代码行数:23,代码来源:init_wsgi_middlewares.py

示例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 
开发者ID:openstack,项目名称:cloudkitty,代码行数:19,代码来源:app.py

示例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 
开发者ID:hashedin,项目名称:squealy,代码行数:10,代码来源:__init__.py

示例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: 
开发者ID:beancount,项目名称:fava,代码行数:59,代码来源:cli.py


注:本文中的werkzeug.middleware.dispatcher.DispatcherMiddleware方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。