예제 #1
0
def FullyWrappedApp(appinfo_external, appengine_config):
    """Completely wraps a user's app per the given YAML file.

  Should only be called once per process. Note that any file referenced in the
  imports of appinfo_external should be written to disk at the corresponding
  relative path.

  Args:
    appinfo_external: an AppInfoExternal for this app, usually (always?) parsed
      from an app.yaml.
    appengine_config: A VmAppengineEnvConfig object.

  Returns:
    A WSGI app, properly scaffolded for the GAE VM runtime.
  """
    app = MetaWSGIApp(appinfo_external, appengine_config)
    app = middlewares.RequestLoggingMiddleware(app)
    app = middlewares.ErrorLoggingMiddleware(app)
    app = middlewares.WsgiEnvSettingMiddleware(app, appinfo_external)
    app = middlewares.FixServerEnvVarsMiddleware(app)
    app = middlewares.OsEnvSetupMiddleware(app, appengine_config)
    app = middlewares.RequestIdMiddleware(app)

    app = middlewares.PatchLoggingMethods(app)
    app = middlewares.LogFlushCounter(app)
    app = middlewares.RequestQueueingMiddleware(app, appinfo_external)
    app = middlewares.UseRequestSecurityTicketForApiMiddleware(app)
    app = middlewares.CallbackMiddleware(app)
    return app
예제 #2
0
def wrap_wsgi_app(app):
    """Wrap a WSGI app with middlewares required to access App Engine APIs."""

    from google.appengine.ext.vmruntime import middlewares
    from google.appengine.ext.vmruntime import vmstub

    vmstub.Register(vmstub.VMStub())

    app = middlewares.ErrorLoggingMiddleware(app)
    app = middlewares.OsEnvSetupMiddleware(app)

    class FakeAppinfoExternal:
        """As we don't have an app.yaml to parse, just assume threadsafe."""
        threadsafe = True

    app = middlewares.WsgiEnvSettingMiddleware(app, FakeAppinfoExternal)
    app = middlewares.WaitForResponseMiddleware(app)
    app = middlewares.UseRequestSecurityTicketForApiMiddleware(app)
    app = middlewares.CallbackMiddleware(app)

    app = middlewares.InitRequestEnvironMiddleware(app,
                                                   copy_gae_application=True)

    return app