-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
36 lines (28 loc) · 744 Bytes
/
app.py
File metadata and controls
36 lines (28 loc) · 744 Bytes
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
#!/usr/bin/env python
# encoding: utf-8
"""
Created on 4/5/17 9:16 PM
@author: Flowsnow
@file: app.py
@function: 实现通用的web框架
"""
from m import M
import json
def jsonify(**kwargs):
"""Support json in M"""
body = json.dumps(kwargs)
return M.Response(body, charset='utf-8', content_type='application/json')
tv = M.Router('/tv')
@tv.get('/{id:int}')
def get_tv(ctx, request):
return jsonify(id=request.vars.id)
if __name__ == '__main__':
app = M()
app.register(tv)
from wsgiref.simple_server import make_server
server = make_server('0.0.0.0', 9000, app)
try:
print('Serving on port 9000...')
server.serve_forever()
except KeyboardInterrupt:
server.shutdown()