-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapache_wsgi.py
50 lines (36 loc) · 1.78 KB
/
apache_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
39
40
41
42
43
44
45
46
47
48
import sys
index = """
<a href="/swgoh/cotd">CoTD Charts</a>
"""
def serve_static_file(filename, start_response):
status = '200 OK'
h = open('/home/amoliski/swgoh/static/{}'.format(filename), 'r')
content = h.read()
h.close()
c_type = 'application/json' if filename.endswith('.json') else 'text/html'
response_headers = [('Content-Type', c_type), ('Content-Length', str(len(content))), ('Access-Control-Allow-Origin',' *')]
start_response(status, response_headers)
return content.encode('utf8')
def application(environ, start_response):
if environ.get('PATH_INFO') == '/':
status = '200 OK'
content = index
response_headers = [('Content-Type', 'text/html'), ('Content-Length', str(len(content))), ('Access-Control-Allow-Origin',' *')]
start_response(status, response_headers)
yield content.encode('utf8')
elif environ.get('PATH_INFO') == '/swgoh/cotd':
yield serve_static_file('index.htm', start_response)
elif environ.get('PATH_INFO') == '/swgoh/cotd/unit_list.json':
yield serve_static_file('unit_list.json', start_response)
elif environ.get('PATH_INFO') == '/swgoh/cotd/rosters.json':
yield serve_static_file('rosters.json', start_response)
elif environ.get('PATH_INFO') == '/swgoh/cotd/user_list.json':
yield serve_static_file('user_list.json', start_response)
elif environ.get('PATH_INFO') == '/swgoh/cache.json':
yield serve_static_file('cache.json', start_response)
else:
status = '404 NOT FOUND'
content = 'Page not found.'
response_headers = [('Content-Type', 'text/html'), ('Content-Length', str(len(content))), ('Access-Control-Allow-Origin',' *')]
start_response(status, response_headers)
yield content.encode('utf8')