-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsgi.py
executable file
·38 lines (28 loc) · 960 Bytes
/
wsgi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
import os
import sys
sys.dont_write_bytecode = True
if os.environ.get('WORKER_CLASS') in ('greenlet', 'gevent'):
# Monkey-patching for gevent.
from gevent import monkey; monkey.patch_all()
# Redirect print statements to stderr
# http://serverfault.com/questions/239614/wsgi-and-python-print-statements#239621
sys.stdout = sys.stderr
# Fix path
path = os.path.dirname(__file__)
if path not in sys.path:
sys.path.append(path)
os.chdir(path)
# import all library code and application packages
sys.path.append(path + '/mopa')
from mopa import create_app
def wsgi_app(environ, start_response):
import sys
output = sys.version.encode('utf8')
status = '200 OK'
headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, headers)
yield output
# mod_wsgi needs a `application` variable in order to serve our app
application = create_app()