def wsgi_apps(): """Wsgi app fixture.""" from invenio_base.wsgi import create_wsgi_factory, wsgi_proxyfix from invenio_base.app import create_app_factory def _config(app, **kwargs): app.config.update(SECRET_KEY='SECRET_KEY', TESTING=True, APP_DEFAULT_SECURE_HEADERS=dict(force_https=False, )) # API create_api = create_app_factory( 'invenio', config_loader=_config, wsgi_factory=wsgi_proxyfix(), ) # UI create_ui = create_app_factory( 'invenio', config_loader=_config, wsgi_factory=wsgi_proxyfix(), ) # Combined create_app = create_app_factory( 'invenio', config_loader=_config, wsgi_factory=wsgi_proxyfix(create_wsgi_factory({'/api': create_api})), ) return create_app, create_ui, create_api
def create_wsgi_statsd_factory(mounts_factories): """Create WSGI statsd factory.""" wsgi_factory = create_wsgi_factory(mounts_factories) def create_wsgi(app, **kwargs): application = wsgi_factory(app, **kwargs) # Remove X-Forwarded-For headers because Flask-Security doesn't know # how to deal with them properly. Note REMOTE_ADDR has already been # set correctly at this point by the ``wsgi_proxyfix`` factory. if app.config.get('WSGI_PROXIES'): application = HeaderRewriterFix( application, remove_headers=['X-Forwarded-For'] ) host = app.config.get('STATSD_HOST') port = app.config.get('STATSD_PORT', 8125) prefix = app.config.get('STATSD_PREFIX') if host and port and prefix: client = StatsClient(prefix=prefix, host=host, port=port) return StatsdTimingMiddleware(application, client) return application return create_wsgi
def create_wsgi_statsd_factory(mounts_factories): """Create WSGI statsd factory.""" wsgi_factory = create_wsgi_factory(mounts_factories) def create_wsgi(app, **kwargs): application = wsgi_factory(app, **kwargs) host = app.config.get('STATSD_HOST') port = app.config.get('STATSD_PORT', 8125) prefix = app.config.get('STATSD_PREFIX') if host and port and prefix: client = StatsClient(prefix=prefix, host=host, port=port) return StatsdTimingMiddleware(application, client) return application return create_wsgi
def test_create_wsgi_factory(): """Test wsgi factory creation.""" api = Flask('api') @api.route('/') def apiview(): return 'api' app = Flask('app') @app.route('/') def appview(): return 'app' # Test factory creation factory = create_wsgi_factory({'/api': lambda **kwargs: api}) app.wsgi_app = factory(app) with app.test_client() as client: assert client.get('/').status_code == 200 assert b'app' in client.get('/').data assert client.get('/api/').status_code == 200 assert b'api' in client.get('/api/').data
def test_create_wsgi_factory(): """Test wsgi factory creation.""" api = Flask("api") @api.route("/") def apiview(): return "api" app = Flask("app") @app.route("/") def appview(): return "app" # Test factory creation factory = create_wsgi_factory({"/api": lambda **kwargs: api}) app.wsgi_app = factory(app) with app.test_client() as client: assert client.get("/").status_code == 200 assert b"app" in client.get("/").data assert client.get("/api/").status_code == 200 assert b"api" in client.get("/api/").data
def create_wsgi_statsd_factory(mounts_factories): """Create WSGI statsd factory.""" wsgi_factory = create_wsgi_factory(mounts_factories) def create_wsgi(app, **kwargs): application = wsgi_factory(app, **kwargs) # Remove X-Forwarded-For headers because Flask-Security doesn't know # how to deal with them properly. Note REMOTE_ADDR has already been # set correctly at this point by the ``wsgi_proxyfix`` factory. if app.config.get('WSGI_PROXIES'): application = HeaderRewriterFix(application, remove_headers=['X-Forwarded-For']) host = app.config.get('STATSD_HOST') port = app.config.get('STATSD_PORT', 8125) prefix = app.config.get('STATSD_PREFIX') if host and port and prefix: client = StatsClient(prefix=prefix, host=host, port=port) return StatsdTimingMiddleware(application, client) return application return create_wsgi
""" static_folder = os.getenv(env_prefix + '_STATIC_FOLDER') or \ os.path.join(instance_path, 'static') """Static folder path. Defaults to ``<env_prefix>_STATIC_FOLDER`` or if environment variable is not set ``<sys.prefix>/var/<app_name>-instance/static``. """ create_api = create_app_factory( 'scoap3', config_loader=config_loader, blueprint_entry_points=['invenio_base.api_blueprints'], extension_entry_points=['invenio_base.api_apps'], converter_entry_points=['invenio_base.api_converters'], instance_path=instance_path, ) create_app = create_app_factory( 'scoap3', config_loader=config_loader, blueprint_entry_points=['invenio_base.blueprints'], extension_entry_points=['invenio_base.apps'], converter_entry_points=['invenio_base.converters'], wsgi_factory=create_wsgi_factory({'/api': create_api}), instance_path=instance_path, static_folder=static_folder, )
set ``<sys.prefix>/var/<app_name>-instance``. """ static_folder = os.getenv(env_prefix + '_STATIC_FOLDER') or \ os.path.join(instance_path, 'static') """Static folder path. Defaults to ``<env_prefix>_STATIC_FOLDER`` or if environment variable is not set ``<sys.prefix>/var/<app_name>-instance/static``. """ create_api = create_app_factory( '{{ cookiecutter.package_name }}', config_loader=config_loader, blueprint_entry_points=['invenio_base.api_blueprints'], extension_entry_points=['invenio_base.api_apps'], converter_entry_points=['invenio_base.api_converters'], instance_path=instance_path, ) create_app = create_app_factory( '{{ cookiecutter.package_name }}', config_loader=config_loader, blueprint_entry_points=['invenio_base.blueprints'], extension_entry_points=['invenio_base.apps'], converter_entry_points=['invenio_base.converters'], wsgi_factory=create_wsgi_factory({'/api': create_api}), instance_path=instance_path, static_folder=static_folder, )
config_loader=config_loader, blueprint_entry_points=['invenio_base.blueprints'], extension_entry_points=['invenio_base.apps'], converter_entry_points=['invenio_base.converters'], wsgi_factory=wsgi_proxyfix(), instance_path=instance_path, static_folder=static_folder, root_path=instance_path, static_url_path=static_url_path(), app_class=app_class(), ) """Flask application factory for Invenio UI.""" create_app = create_app_factory( 'invenio', config_loader=config_loader, blueprint_entry_points=['invenio_base.blueprints'], extension_entry_points=['invenio_base.apps'], converter_entry_points=['invenio_base.converters'], wsgi_factory=wsgi_proxyfix(create_wsgi_factory({'/api': create_api})), instance_path=instance_path, static_folder=static_folder, root_path=instance_path, static_url_path=static_url_path(), app_class=app_class(), ) """Flask application factory for combined UI + REST API. REST API is mounted under ``/api``. """
# sphinxdoc-example-paths-end # sphinxdoc-example-factories-begin create_api = create_app_factory( "example", config_loader=config_loader, blueprint_entry_points=["invenio_base.api_blueprints"], extension_entry_points=["invenio_base.api_apps"], converter_entry_points=["invenio_base.api_converters"], instance_path=instance_path, ) create_app = create_app_factory( "example", config_loader=config_loader, blueprint_entry_points=["invenio_base.blueprints"], extension_entry_points=["invenio_base.apps"], converter_entry_points=["invenio_base.converters"], wsgi_factory=create_wsgi_factory({"/api": create_api}), instance_path=instance_path, static_folder=static_folder, ) # sphinxdoc-example-factories-end # sphinxdoc-example-objects-begin app = application = create_app() """The application object.""" # sphinxdoc-example-objects-end
config_loader=conf_loader, blueprint_entry_points=['invenio_base.api_blueprints'], extension_entry_points=['invenio_base.api_apps'], converter_entry_points=['invenio_base.api_converters'], instance_path=instance_path, static_folder=static_folder, ) # create_app = create_app_factory( # 'cap', # config_loader=conf_loader, # blueprint_entry_points=['invenio_base.blueprints'], # extension_entry_points=['invenio_base.apps'], # instance_path=instance_path, # static_folder=static_folder, # ) create_front = create_app_factory( 'cap', config_loader=conf_loader, blueprint_entry_points=['cap.blueprints'], extension_entry_points=['cap.apps'], instance_path=instance_path, static_folder=static_folder, wsgi_factory=wsgi_proxyfix( create_wsgi_factory({ '/api': create_api, # '/app': create_app, #TODO Remove this when everything restful })), )
environment variable ``APP_INSTANCE_PATH``. """ static_folder = os.getenv(env_prefix + "_STATIC_FOLDER") or os.path.join(instance_path, "static") """Path to static folder. Defaults to ``<virtualenv>/var/zenodo-instance/static/``. Can be overwritten using the environment variable ``APP_STATIC_FOLDER`` """ create_api = create_app_factory( "zenodo", config_loader=conf_loader, extension_entry_points=["invenio_base.api_apps"], blueprint_entry_points=["invenio_base.api_blueprints"], instance_path=instance_path, ) """Create Flask API application.""" create_app = create_app_factory( "zenodo", config_loader=conf_loader, extension_entry_points=["invenio_base.apps"], blueprint_entry_points=["invenio_base.blueprints"], wsgi_factory=create_wsgi_factory({"/api": create_api}), instance_path=instance_path, static_folder=static_folder, ) """Create Flask UI application."""
converter_entry_points=['invenio_base.api_converters'], instance_path=instance_path, static_folder=static_folder, ) create_app = create_app_factory( 'cap', config_loader=conf_loader, blueprint_entry_points=['invenio_base.blueprints'], extension_entry_points=['invenio_base.apps'], instance_path=instance_path, static_folder=static_folder, ) create_front = create_app_factory( 'cap', config_loader=conf_loader, blueprint_entry_points=['cap.blueprints'], extension_entry_points=['cap.apps'], instance_path=instance_path, static_folder=static_folder, wsgi_factory=wsgi_proxyfix( create_wsgi_factory({ '/api': create_api, '/app': create_app, })), )