Created
February 16, 2016 09:23
-
-
Save renaud/d4ed613ea7a742a3e0fa to your computer and use it in GitHub Desktop.
Tornado REST server base template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
REST endpoint | |
''' | |
import os, json | |
from datetime import date | |
from tornado import ioloop, web, autoreload | |
''' serves index.html''' | |
class MainHandler(web.RequestHandler): | |
def get(self): | |
self.render('app/index.html') | |
class XXXHandler(web.RequestHandler): | |
def get(self, xxx): | |
self.write(json.dumps( xxx )) | |
application = web.Application([ | |
(r'/', MainHandler), | |
(r"/xxxx/(.+)", XXXHandler), | |
(r'/app/(.*)', web.StaticFileHandler, {'path': 'app/'}) | |
],gzip=True) | |
if __name__ == "__main__": | |
application.listen(8875) | |
autoreload.start() #TODO remove in prod | |
for dir, _, files in os.walk('app'): | |
[autoreload.watch(dir + '/' + f) for f in files if not f.startswith('.')] | |
ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment