-
Notifications
You must be signed in to change notification settings - Fork 32
/
web-uwsgi.py
35 lines (27 loc) · 1.04 KB
/
web-uwsgi.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
import uwsgi
import zmq
import struct
COMMON_HEADERS = [('Content-Type', 'application/json'), ('Access-Control-Allow-Origin', '*'), ('Access-Control-Allow-Headers', 'Requested-With,Content-Type')]
context = zmq.Context()
def light(environ, start_response):
if environ['PATH_INFO'] in ['/favicon.ico']:
start_response('404 NOK', COMMON_HEADERS)
return ''
qstring = environ['QUERY_STRING']
if qstring == '':
start_response('406 NOK', COMMON_HEADERS)
return ''
request_bliksem = context.socket(zmq.REQ)
request_bliksem.connect("tcp://127.0.0.1:9292")
poller = zmq.Poller()
poller.register(request_bliksem, zmq.POLLIN)
request_bliksem.send(qstring)
socks = dict(poller.poll(1000))
if socks.get(request_bliksem) == zmq.POLLIN:
reply = request_bliksem.recv()
start_response('200 OK', COMMON_HEADERS + [('Content-length', str(len(reply)))])
return reply
else:
start_response('500 NOK', COMMON_HEADERS)
return ''
uwsgi.applications = {'': light}