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