~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to serve-branches

  • Committer: Michael Hudson
  • Date: 2009-03-04 21:02:14 UTC
  • Revision ID: michael.hudson@canonical.com-20090304210214-1ekwse6xtm2ydb0w
some NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from optparse import OptionParser
23
23
 
 
24
from bzrlib.plugin import load_plugins
 
25
 
24
26
from paste import httpserver
25
 
from paste.httpexceptions import HTTPExceptionHandler
 
27
from paste.httpexceptions import HTTPExceptionHandler, HTTPInternalServerError
26
28
from paste.translogger import TransLogger
27
29
 
28
30
from loggerhead import __version__
116
118
    logfile.setLevel(logging.DEBUG)
117
119
    logger.addHandler(logfile)
118
120
    # setup_logging() #end
119
 
    app = ErrorHandlerApp(app)
120
 
    app = HTTPExceptionHandler(app)
121
121
    app = TransLogger(app, logger=logger)
122
122
    if options.profile:
123
123
        from loggerhead.middleware.profile import LSProfMiddleware
127
127
        prefix = '/'
128
128
    else:
129
129
        prefix = options.user_prefix
 
130
        if not prefix.startswith('/'):
 
131
            prefix = '/' + prefix
130
132
 
131
133
    try:
132
134
        from paste.deploy.config import PrefixMiddleware
133
135
    except ImportError:
134
 
        pass
 
136
        cant_proxy_correctly_message = (
 
137
            'Unsupported configuration: PasteDeploy not available, but '
 
138
            'loggerhead appears to be behind a proxy.')
 
139
        def check_not_proxied(app):
 
140
            def wrapped(environ, start_response):
 
141
                if 'HTTP_X_FORWARDED_SERVER' in environ:
 
142
                    exc = HTTPInternalServerError()
 
143
                    exc.explanation = cant_proxy_correctly_message
 
144
                    raise exc
 
145
                return app(environ, start_response)
 
146
            return wrapped
 
147
        app = check_not_proxied(app)
135
148
    else:
136
149
        app = PrefixMiddleware(app, prefix=prefix)
137
150
 
 
151
    app = HTTPExceptionHandler(app)
 
152
    app = ErrorHandlerApp(app)
 
153
 
138
154
    if not options.user_port:
139
155
        port = '8080'
140
156
    else:
145
161
    else:
146
162
        host = options.user_host
147
163
 
 
164
    load_plugins()
 
165
 
148
166
    httpserver.serve(app, host=host, port=port)
149
167
 
150
168