Show More
@@ -1,84 +1,86 b'' | |||
|
1 | 1 | """Pylons middleware initialization""" |
|
2 | 2 | |
|
3 | 3 | from beaker.middleware import SessionMiddleware |
|
4 | 4 | from routes.middleware import RoutesMiddleware |
|
5 | 5 | from paste.cascade import Cascade |
|
6 | 6 | from paste.registry import RegistryManager |
|
7 | 7 | from paste.urlparser import StaticURLParser |
|
8 | 8 | from paste.deploy.converters import asbool |
|
9 | 9 | from paste.gzipper import make_gzip_middleware |
|
10 | 10 | |
|
11 | 11 | from pylons.middleware import ErrorHandler, StatusCodeRedirect |
|
12 | 12 | from pylons.wsgiapp import PylonsApp |
|
13 | 13 | |
|
14 | 14 | from rhodecode.lib.middleware.simplehg import SimpleHg |
|
15 | 15 | from rhodecode.lib.middleware.simplegit import SimpleGit |
|
16 | 16 | from rhodecode.lib.middleware.https_fixup import HttpsFixup |
|
17 | 17 | from rhodecode.config.environment import load_environment |
|
18 | 18 | |
|
19 | 19 | |
|
20 | 20 | def make_app(global_conf, full_stack=True, static_files=True, **app_conf): |
|
21 | 21 | """Create a Pylons WSGI application and return it |
|
22 | 22 | |
|
23 | 23 | ``global_conf`` |
|
24 | 24 | The inherited configuration for this application. Normally from |
|
25 | 25 | the [DEFAULT] section of the Paste ini file. |
|
26 | 26 | |
|
27 | 27 | ``full_stack`` |
|
28 | 28 | Whether or not this application provides a full WSGI stack (by |
|
29 | 29 | default, meaning it handles its own exceptions and errors). |
|
30 | 30 | Disable full_stack when this application is "managed" by |
|
31 | 31 | another WSGI middleware. |
|
32 | 32 | |
|
33 | 33 | ``app_conf`` |
|
34 | 34 | The application's local configuration. Normally specified in |
|
35 | 35 | the [app:<name>] section of the Paste ini file (where <name> |
|
36 | 36 | defaults to main). |
|
37 | 37 | |
|
38 | 38 | """ |
|
39 | 39 | # Configure the Pylons environment |
|
40 | 40 | config = load_environment(global_conf, app_conf) |
|
41 | 41 | |
|
42 | 42 | # The Pylons WSGI app |
|
43 | 43 | app = PylonsApp(config=config) |
|
44 | 44 | |
|
45 | 45 | # Routing/Session/Cache Middleware |
|
46 | 46 | app = RoutesMiddleware(app, config['routes.map']) |
|
47 | 47 | app = SessionMiddleware(app, config) |
|
48 | 48 | |
|
49 | 49 | # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) |
|
50 | 50 | if asbool(config['pdebug']): |
|
51 | 51 | from rhodecode.lib.profiler import ProfilingMiddleware |
|
52 | 52 | app = ProfilingMiddleware(app) |
|
53 | 53 | |
|
54 | ||
|
55 | # we want our low level middleware to get to the request ASAP. We don't | |
|
56 | # need any pylons stack middleware in them | |
|
57 | app = SimpleHg(app, config) | |
|
58 | app = SimpleGit(app, config) | |
|
59 | ||
|
54 | 60 | if asbool(full_stack): |
|
55 | 61 | # Handle Python exceptions |
|
56 | 62 | app = ErrorHandler(app, global_conf, **config['pylons.errorware']) |
|
57 | 63 | |
|
58 | 64 | # Display error documents for 401, 403, 404 status codes (and |
|
59 | 65 | # 500 when debug is disabled) |
|
60 | 66 | if asbool(config['debug']): |
|
61 | 67 | app = StatusCodeRedirect(app) |
|
62 | 68 | else: |
|
63 | 69 | app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) |
|
64 | 70 | |
|
65 | 71 | #enable https redirets based on HTTP_X_URL_SCHEME set by proxy |
|
66 | 72 | app = HttpsFixup(app, config) |
|
67 | 73 | |
|
68 | 74 | # Establish the Registry for this application |
|
69 | 75 | app = RegistryManager(app) |
|
70 | 76 | |
|
71 | 77 | if asbool(static_files): |
|
72 | 78 | # Serve static files |
|
73 | 79 | static_app = StaticURLParser(config['pylons.paths']['static_files']) |
|
74 | 80 | app = Cascade([static_app, app]) |
|
75 | 81 | app = make_gzip_middleware(app, global_conf, compress_level=1) |
|
76 | 82 | |
|
77 | # we want our low level middleware to get to the request ASAP. We don't | |
|
78 | # need any pylons stack middleware in them | |
|
79 | app = SimpleHg(app, config) | |
|
80 | app = SimpleGit(app, config) | |
|
81 | 83 | |
|
82 | 84 | app.config = config |
|
83 | 85 | |
|
84 | 86 | return app |
General Comments 0
You need to be logged in to leave comments.
Login now