-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsgi.py
50 lines (30 loc) · 1.21 KB
/
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
49
50
import sys
from importlib import import_module
from Illuminate.Http.ServerBag.WSGIServer import WSGIServer
from werkzeug.middleware.shared_data import SharedDataMiddleware
def clear_module_cache(module_name):
if module_name in sys.modules:
del sys.modules[module_name]
class WSGIApplication:
def __init__(self) -> None:
from bootstrap.app import app
self.public_path = app.public_path()
self.events = app.make("events")
self.response = None
def __call__(self, environ, start_response):
try:
clear_module_cache("public.index")
WSGIServer.create_server(environ, start_response)
self.events.listen(
"response_sent",
lambda response: self.on_response(response, start_response),
)
import_module("public.index")
return self.response
except Exception as e:
print(e)
def on_response(self, response, start_response):
start_response(response.get_status_code(), response.get_headers())
self.response = [response.get_content().encode("utf-8")]
app = WSGIApplication()
app = SharedDataMiddleware(app, {"/": str(app.public_path)})