-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
50 lines (40 loc) · 1.11 KB
/
app.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
import gevent
import os
from flask import Flask, render_template, request
from gevent import monkey
from socketio import socketio_manage
from socketio.server import SocketIOServer
from werkzeug.wsgi import SharedDataMiddleware
from consumer import consumer_service
from dashboardio import DashboardIOApp
from models import DataSetHandler
monkey.patch_all()
app = Flask(__name__)
app.debug = True
data_set_handler = DataSetHandler()
@app.route("/")
def home():
return render_template("index.html")
@app.route('/socket.io/<path:path>')
def socketio_server(path):
socketio_manage(
request.environ,
{'': DashboardIOApp},
request=data_set_handler
)
return {}
def main():
http_app = SharedDataMiddleware(app, {
'/': os.path.join(os.path.dirname(__file__), 'static')
})
socket_server = SocketIOServer(
('', 8000), http_app,
namespace='socket.io',
policy_server=False
)
gevent.joinall([
gevent.spawn(socket_server.serve_forever),
gevent.spawn(consumer_service, data_set_handler)
])
if __name__ == "__main__":
main()