Skip to content

Instantly share code, notes, and snippets.

@an01f01
Created October 11, 2024 20:51
Show Gist options
  • Save an01f01/75a70945b37a721b88d4c05f9a60296d to your computer and use it in GitHub Desktop.
Save an01f01/75a70945b37a721b88d4c05f9a60296d to your computer and use it in GitHub Desktop.
def make_app():
settings = dict(
cookie_secret=str(os.urandom(45)),
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
default_handler_class=ErrorHandler,
default_handler_args=dict(status_code=404)
)
return tornado.web.Application([
(r"/", StatusHandler),
(r"/upload", UploadHandler),
(r"/api", FileUploadHandler),
], **settings)
async def main():
# Create the uploads directory if it doesn't exist
if not os.path.exists('uploads'):
os.makedirs('uploads')
print(f"🚀 Starting stats tornado server.......... http://localhost:{tornado.options.options.port}")
app = make_app()
app.listen(tornado.options.options.port)
await asyncio.Event().wait()
if __name__ == '__main__':
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment