|
6 | 6 | named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover |
7 | 7 | this application via the ``WSGI_APPLICATION`` setting. |
8 | 8 |
|
9 | | -Usually you will have the standard Django WSGI application here, but it also |
10 | | -might make sense to replace the whole Django WSGI application with a custom one |
11 | | -that later delegates to the Django one. For example, you could introduce WSGI |
12 | | -middleware here, or combine a Django application with an application of another |
13 | | -framework. |
14 | | -
|
15 | 9 | """ |
16 | 10 |
|
17 | 11 | from __future__ import unicode_literals |
18 | 12 | import os |
19 | 13 |
|
20 | | -# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks |
21 | | -# if running multiple sites in the same mod_wsgi process. To fix this, use |
22 | | -# mod_wsgi daemon mode with each site in its own daemon process, or use |
23 | | -# os.environ["DJANGO_SETTINGS_MODULE"] = "deis.settings" |
| 14 | +from django.core.wsgi import get_wsgi_application |
| 15 | +import static |
| 16 | + |
| 17 | + |
24 | 18 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "deis.settings") |
25 | 19 |
|
26 | | -# This application object is used by any WSGI server configured to use this |
27 | | -# file. This includes Django's development server, if the WSGI_APPLICATION |
28 | | -# setting points here. |
29 | | -from django.core.wsgi import get_wsgi_application |
30 | | -application = get_wsgi_application() |
31 | 20 |
|
32 | | -# Apply WSGI middleware here. |
33 | | -# from helloworld.wsgi import HelloWorldApplication |
34 | | -# application = HelloWorldApplication(application) |
| 21 | +class Dispatcher(object): |
| 22 | + """ |
| 23 | + Dispatches requests between two WSGI apps, a static file server and a |
| 24 | + Django server. |
| 25 | + """ |
| 26 | + |
| 27 | + def __init__(self): |
| 28 | + self.django_handler = get_wsgi_application() |
| 29 | + self.static_handler = static.Cling(os.path.dirname(os.path.dirname(__file__))) |
| 30 | + |
| 31 | + def __call__(self, environ, start_response): |
| 32 | + if environ['PATH_INFO'].startswith('/static'): |
| 33 | + return self.static_handler(environ, start_response) |
| 34 | + else: |
| 35 | + return self.django_handler(environ, start_response) |
| 36 | + |
| 37 | + |
| 38 | +application = Dispatcher() |
0 commit comments