-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcathedral.py
33 lines (30 loc) · 1.16 KB
/
cathedral.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
from tower_manager import load_towers, handle_route
import asyncio
from aiohttp import web
from re import compile, match
import auth
class cathedral():
def __init__(self, settings):
self.cfg = settings
self.towers = load_towers(self.cfg.get("PLUGIN_PATH"))
self.auth = auth
async def handle_http(self, r):
for t in self.towers:
for h in t.hooks:
if compile(h.replace("$HOST", str(r.host)[str(r.host).find(self.cfg.get("base")):])).match(str(r.url)):
return web.Response(**t.run(self, r))
return web.Response(body=f"usergroup homepage")
async def start_http(self):
srv = web.Server(self.handle_http)
runner = web.ServerRunner(srv)
await runner.setup()
site = web.TCPSite(runner, self.cfg.get("host"), self.cfg.get("port"))
await site.start()
print(f"serving @ {self.cfg.get('host')}:{self.cfg.get('port')}...")
await asyncio.sleep(3600*24*365)
def erect(self):
l = asyncio.get_event_loop()
try: l.run_until_complete(self.start_http())
except Exception as e:
print(e)
l.close()