-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.py
70 lines (50 loc) · 1.5 KB
/
server.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
import responder
from datetime import datetime
from db import Entry, db
api = responder.API()
env = os.environ.get('PYENV', 'DEBUG')
__version__ = 'v0.0.1'
__author__ = "JG (之及)"
def __initalize_runserver__():
db.connect()
db.create_tables([Entry, ])
api.run(address="0.0.0.0", debug=env=='DEBUG', workers=1)
@api.route('/')
async def index(req, resp):
resp.html = api.template('index.html')
@api.route('/{location}/inspect')
async def inspect(req, resp, *, location):
if len(location) != 32:
resp.text = "location must be UUID."
resp.status_code = api.status_codes.bad
return
entrys = Entry.select().where(
Entry.location==location
).order_by(Entry.time.desc())
resp.html = api.template('inspect.html', **locals())
@api.route('/{location}')
async def meta(req, resp, *, location):
if len(location) != 32:
resp.text = "location must be UUID."
resp.status_code = api.status_codes.bad
return
data = {
"path": req.full_url,
"method": req.method,
"params": req.params,
"headers": dict(req.headers),
"body": await req.text,
"cookies": req.cookies
}
Entry.create(location=location, time=datetime.now(), data=data)
resp.media = {"status": "ok"}
@api.route('/ping')
async def ping(req, resp):
resp.media = {
"_": "pong",
"version": __version__,
"author": __author__,
}
if __name__ == '__main__':
__initalize_runserver__()