Skip to content

Commit 2a5439e

Browse files
mboersmaGabriel Monroy
authored andcommitted
Added static file serving WSGI app, fixes #507.
1 parent 89e649e commit 2a5439e

7 files changed

Lines changed: 27 additions & 27 deletions

File tree

Procfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
web: gunicorn_django -c gconfig.py
1+
web: gunicorn deis.wsgi -b 0.0.0.0:8000 -w 8 -n deis --log-level debug

deis/wsgi.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,33 @@
66
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
77
this application via the ``WSGI_APPLICATION`` setting.
88
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-
159
"""
1610

1711
from __future__ import unicode_literals
1812
import os
1913

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+
2418
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "deis.settings")
2519

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()
3120

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()

dev_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ python-etcd==0.3.0
1717
pyrax==1.6.2
1818
PyYAML==3.10
1919
redis==2.8.0
20+
static==1.0.2
2021
South==0.8.4
2122

2223
# Deis client requirements

gconfig.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

images/server

images/worker

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ python-etcd==0.3.0
1717
pyrax==1.6.2
1818
PyYAML==3.10
1919
redis==2.8.0
20+
static==1.0.2
2021
South==0.8.4

0 commit comments

Comments
 (0)