diff --git a/pylons_app/config/middleware.py b/pylons_app/config/middleware.py --- a/pylons_app/config/middleware.py +++ b/pylons_app/config/middleware.py @@ -1,10 +1,9 @@ """Pylons middleware initialization""" -from beaker.middleware import CacheMiddleware, SessionMiddleware +from beaker.middleware import SessionMiddleware from paste.cascade import Cascade from paste.registry import RegistryManager from paste.urlparser import StaticURLParser from paste.deploy.converters import asbool -from pylons import config from pylons.middleware import ErrorHandler, StatusCodeRedirect from pylons.wsgiapp import PylonsApp from routes.middleware import RoutesMiddleware @@ -12,7 +11,7 @@ from paste.auth.basic import AuthBasicHa from pylons_app.config.environment import load_environment from pylons_app.lib.auth import authfunc -def make_app(global_conf, full_stack=True, **app_conf): +def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` @@ -32,17 +31,17 @@ def make_app(global_conf, full_stack=Tru """ # Configure the Pylons environment - load_environment(global_conf, app_conf) + config = load_environment(global_conf, app_conf) + # The Pylons WSGI app - app = PylonsApp() + app = PylonsApp(config=config) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) - app = CacheMiddleware(app, config) app = AuthBasicHandler(app, config['repos_name'] + ' mercurial repository', authfunc) if asbool(full_stack): @@ -53,16 +52,19 @@ def make_app(global_conf, full_stack=Tru # 500 when debug is disabled) if asbool(config['debug']): #don't handle 404, since mercurial does it for us. - app = StatusCodeRedirect(app, [400, 401, 403, 500]) + app = StatusCodeRedirect(app, [400, 401, 403]) else: app = StatusCodeRedirect(app, [400, 401, 403, 500]) # Establish the Registry for this application app = RegistryManager(app) - # Static files (If running in production, and Apache or another web - # server is handling this static content, remove the following 3 lines) - static_app = StaticURLParser(config['pylons.paths']['static_files']) - app = Cascade([static_app, app]) + if asbool(static_files): + # Serve static files + static_app = StaticURLParser(config['pylons.paths']['static_files']) + app = Cascade([static_app, app]) + + app.config = config + return app