-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
36 lines (28 loc) · 1.12 KB
/
main.py
File metadata and controls
36 lines (28 loc) · 1.12 KB
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
from flask import Flask
from flask_cors import CORS
from flask_socketio import SocketIO
from flask_restx import Api, Resource
from config import get_config
from sockets.base_events import connect, user_disconnect
from sockets.user_events.room import on_join, on_leave
from sockets.user_events.auth import user_connection
from sockets.user_events import sent_message
config = get_config()
app = Flask(__name__)
app.config['SECRET_KEY'] = config['GENERAL']['COOKIE_SECRET']
#services
CORS(app, resources={r"*": {"origins": "http://localhost:3000"}})
api = Api(app)
socketio = SocketIO(app, cors_allowed_origins="*")
socketio.on_event('connect', connect)
socketio.on_event('disconnect', user_disconnect)
socketio.on_event('join_chat_room', on_join)
socketio.on_event('leave_chat_room', on_leave)
socketio.on_event('user_connect', user_connection)
socketio.on_event('sent_message', sent_message)
@api.route('/test')
class index(Resource):
def get(self):
return {'title': 'chat', 'developed_by': 'CodeTriarii'}
if __name__ == '__main__':
socketio.run(app, host=config["GENERAL"]["HOST"], port=int(config["GENERAL"]["PORT"]))