-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.py
executable file
·50 lines (38 loc) · 1.45 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
#!/usr/bin/env python
import tornado.ioloop
import tornado.web
import tornado.httpserver
import tornado.options
import logging
import os
tornado.options.define('port', type=int, default=9000, help='server port number (default: 9000)')
tornado.options.define('debug', type=bool, default=False, help='run in debug mode with autoreload (default: False)')
class TodoHandler(tornado.web.RequestHandler):
def get(self, id=None):
self.finish('1')
def post(self, id=None):
self.finish('1')
def delete(self, id=None):
self.finish('1')
class App(tornado.web.Application):
def __init__(self, *args, **kwargs):
settings = {
"static_path" : os.path.join(os.path.dirname(__file__), "public"),
"static_url_prefix" : '/public/',
"debug" : kwargs.get('debug', False),
}
routes = [
(r"/todo/?([^/]*)", TodoHandler),
(r"/([^/]*)", tornado.web.StaticFileHandler, {
'path' : settings['static_path'],
'default_filename' : 'index.html'
}),
]
super(App, self).__init__(routes, **settings)
if __name__ == "__main__":
tornado.options.parse_command_line()
options = tornado.options.options
server = tornado.httpserver.HTTPServer(App(debug=options.debug))
server.listen(options.port)
logging.info('started on port: %d', options.port);
tornado.ioloop.IOLoop.instance().start()