Skip to content

Instantly share code, notes, and snippets.

@renaud
Created February 16, 2016 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renaud/d4ed613ea7a742a3e0fa to your computer and use it in GitHub Desktop.
Save renaud/d4ed613ea7a742a3e0fa to your computer and use it in GitHub Desktop.
Tornado REST server base template
'''
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