-
Notifications
You must be signed in to change notification settings - Fork 0
/
tornado_main.py
49 lines (43 loc) · 1.5 KB
/
tornado_main.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
#!/usr/bin/env python
# Run this with
# PYTHONPATH=. DJANGO_SETTINGS_MODULE=testsite.settings testsite/tornado_main.py
# Serves by default at
# http://localhost:8080/hello-tornado and
# http://localhost:8080/hello-django
import sys
import os
sys.path.append(os.path.abspath('..'))
from bloop import settings
#from django.core.management import setup_environ
#setup_environ(settings)
from tornado.options import options, define, parse_command_line
import django.core.handlers.wsgi
import tornado.httpserver
import tornado.ioloop
import tornado.web
import tornado.wsgi
from chat.chatdemo import *
define('port', type=int, default=8080)
addr="0.0.0.0"
def main():
wsgi_app = tornado.wsgi.WSGIContainer(
django.core.handlers.wsgi.WSGIHandler())
tornado_settings = dict(
cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
xsrf_cookies=True,
autoescape=None,
)
tornado_app = tornado.web.Application([
(r"/chat", MainHandler),
(r"/chat/chatsocket", ChatSocketHandler),
('.*', tornado.web.FallbackHandler, dict(fallback=wsgi_app)),
], **tornado_settings)
server = tornado.httpserver.HTTPServer(tornado_app)
server.listen(options.port, address=addr)
print "Started Tornado web server"
tornado.ioloop.IOLoop.instance().start()
if __name__ == '__main__':
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bloop.settings")
main()