##// END OF EJS Templates
assets: skip RoutesMiddleware matching on certain urls to avoid...
dan -
r463:7ccc440b default
parent child Browse files
Show More
@@ -41,6 +41,7 b' import routes.util'
41 41 import rhodecode
42 42 import rhodecode.integrations # do not remove this as it registers celery tasks
43 43 from rhodecode.config import patches
44 from rhodecode.config.routing import STATIC_FILE_PREFIX
44 45 from rhodecode.config.environment import (
45 46 load_environment, load_pyramid_environment)
46 47 from rhodecode.lib.middleware import csrf
@@ -54,6 +55,25 b' from rhodecode.lib.plugins.utils import '
54 55 log = logging.getLogger(__name__)
55 56
56 57
58 # this is used to avoid avoid the route lookup overhead in routesmiddleware
59 # for certain routes which won't go to pylons to - eg. static files, debugger
60 # it is only needed for the pylons migration and can be removed once complete
61 class SkippableRoutesMiddleware(RoutesMiddleware):
62 """ Routes middleware that allows you to skip prefixes """
63
64 def __init__(self, *args, **kw):
65 self.skip_prefixes = kw.pop('skip_prefixes', [])
66 super(SkippableRoutesMiddleware, self).__init__(*args, **kw)
67
68 def __call__(self, environ, start_response):
69 for prefix in self.skip_prefixes:
70 if environ['PATH_INFO'].startswith(prefix):
71 return self.app(environ, start_response)
72
73 return super(SkippableRoutesMiddleware, self).__call__(
74 environ, start_response)
75
76
57 77 def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
58 78 """Create a Pylons WSGI application and return it
59 79
@@ -142,8 +162,8 b' def make_pyramid_app(global_config, **se'
142 162
143 163 load_pyramid_environment(global_config, settings)
144 164
165 includeme_first(config)
145 166 includeme(config)
146 includeme_last(config)
147 167 pyramid_app = config.make_wsgi_app()
148 168 pyramid_app = wrap_app_in_wsgi_middlewares(pyramid_app, config)
149 169 return pyramid_app
@@ -285,20 +305,17 b' def includeme(config):'
285 305 config.add_view(error_handler, context=HTTPError)
286 306
287 307
288 def includeme_last(config):
289 """
290 The static file catchall needs to be last in the view configuration.
291 """
292 settings = config.registry.settings
293 config.add_static_view('_static', path='rhodecode:public')
294
308 def includeme_first(config):
295 309 # redirect automatic browser favicon.ico requests to correct place
296 310 def favicon_redirect(context, request):
297 311 return redirect(
298 312 request.static_url('rhodecode:public/images/favicon.ico'))
313
299 314 config.add_view(favicon_redirect, route_name='favicon')
300 315 config.add_route('favicon', '/favicon.ico')
301 316
317 config.add_static_view('_static', path='rhodecode:public')
318
302 319
303 320 def wrap_app_in_wsgi_middlewares(pyramid_app, config):
304 321 """
@@ -314,10 +331,10 b' def wrap_app_in_wsgi_middlewares(pyramid'
314 331 pyramid_app = HttpsFixup(pyramid_app, settings)
315 332
316 333 # Add RoutesMiddleware to support the pylons compatibility tween during
317
318 334 # migration to pyramid.
319 pyramid_app = RoutesMiddleware(
320 pyramid_app, config.registry._pylons_compat_config['routes.map'])
335 pyramid_app = SkippableRoutesMiddleware(
336 pyramid_app, config.registry._pylons_compat_config['routes.map'],
337 skip_prefixes=(STATIC_FILE_PREFIX, '/_debug_toolbar'))
321 338
322 339 if asbool(settings.get('appenlight', 'false')):
323 340 pyramid_app, _ = wrap_in_appenlight_if_enabled(
@@ -36,6 +36,7 b' from rhodecode.config import routing_lin'
36 36
37 37 # prefix for non repository related links needs to be prefixed with `/`
38 38 ADMIN_PREFIX = '/_admin'
39 STATIC_FILE_PREFIX = '/_static'
39 40
40 41 # Default requirements for URL parts
41 42 URL_NAME_REQUIREMENTS = {
General Comments 0
You need to be logged in to leave comments. Login now