source: MILK/trunk/milk_server/milk_server/config/middleware.py @ 4485

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/MILK/trunk/milk_server/milk_server/config/middleware.py@4485
Revision 4485, 3.0 KB checked in by cbyrom, 12 years ago (diff)

Rename of middleware class.

Line 
1from paste import httpexceptions
2from paste.cascade import Cascade
3from paste.urlparser import StaticURLParser
4from paste.registry import RegistryManager
5from paste.deploy.config import ConfigMiddleware, CONFIG
6from paste.deploy.converters import asbool
7
8from pylons import config
9from pylons.error import error_template
10from pylons.middleware import ErrorHandler, ErrorDocuments, StaticJavascripts, error_mapper
11from pylons.wsgiapp import PylonsApp
12
13from milk_server.config.environment import load_environment
14
15from milk_server.config.milkMiddleware import milkMiddleware
16
17# Logging doesn't need configuring if you have paste.translogger in your config file.
18#import logging
19
20def make_app(global_conf, full_stack=True, **app_conf):
21    """Create a WSGI application and return it
22   
23    global_conf is a dict representing the Paste configuration options, the
24    paste.deploy.converters should be used when parsing Paste config options
25    to ensure they're treated properly.
26   
27    """
28    # Setup the Paste CONFIG object, adding app_conf/global_conf for legacy code
29    conf = global_conf.copy()
30    conf.update(app_conf)
31    conf.update(dict(app_conf=app_conf, global_conf=global_conf))
32    CONFIG.push_process_config(conf)
33
34    # Load our Pylons configuration defaults
35    load_environment(global_conf, app_conf)
36       
37    # Load our default Pylons WSGI app and make g available
38    app = PylonsApp()
39    g = app.globals
40    app = ConfigMiddleware(app, conf)
41   
42    # YOUR MIDDLEWARE
43    # Put your own middleware here, so that any problems are caught by the error
44    # handling middleware underneath
45    app = milkMiddleware(app, g, app_conf)
46    g=app.globals   
47   
48    # Configure logging - NB logging config set in the development.ini file
49    #logging.basicConfig(format='%(thread)s %(name)s %(levelname)s %(message)s')
50   
51    # If errror handling and exception catching will be handled by middleware
52    # for multiple apps, you will want to set full_stack = False in your config
53    # file so that it can catch the problems.
54    if asbool(full_stack):
55        # Change HTTPExceptions to HTTP responses
56        app = httpexceptions.make_middleware(app, global_conf)
57   
58        # Error Handling
59        app = ErrorHandler(app, global_conf, error_template=error_template, **config['pylons.errorware'])
60   
61        # Display error documents for 401, 403, 404 status codes (if debug is disabled also
62        # intercepts 500)
63        #app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf)
64   
65    # Establish the Registry for this application
66    app = RegistryManager(app)
67   
68    # Allow static files from outside the egg too ... g.htdocs defined in ndgDiscovery.config
69    if g.htdocs:
70        static_paths = [g.htdocs,config['pylons.paths']['static_files']]
71    else: static_paths= [config['pylons.paths']['static_files']]
72    static_app = [StaticURLParser(path) for path in static_paths]
73    javascripts_app = StaticJavascripts()
74    app = Cascade(static_app +[javascripts_app, app])
75    return app
Note: See TracBrowser for help on using the repository browser.