54 lines
1.2 KiB
Python
54 lines
1.2 KiB
Python
import random
|
|
|
|
from flask import Flask, request
|
|
from flask_cors import CORS
|
|
from flask_jwt_extended import JWTManager, jwt_required
|
|
from flask_socketio import SocketIO
|
|
|
|
from database import db
|
|
|
|
app = Flask(__name__)
|
|
cors = CORS(app)
|
|
sio = SocketIO(app, cors_allowed_origins='*')
|
|
|
|
|
|
@app.route('/')
|
|
@jwt_required
|
|
def home():
|
|
return {'url': '/', 'body': 'test body'}
|
|
|
|
|
|
@app.route('/rest')
|
|
def rest():
|
|
return 'rest test'
|
|
|
|
|
|
@sio.on('connect')
|
|
def connected():
|
|
print(f'CONNECTED: {request.sid} ({request.namespace})')
|
|
|
|
|
|
@sio.on('test')
|
|
def test(user):
|
|
senders = ['Aang', 'Inner AAng']
|
|
print(f'TEST: {user} ({request.sid})')
|
|
sio.emit('public message', {'sender': random.choice(senders), 'message': 'Flameo!'})
|
|
|
|
|
|
@sio.on('public message')
|
|
def public_message(kwargs):
|
|
print(kwargs)
|
|
sio.emit('public message', kwargs)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
from auth.auth import auth as auth_blueprint
|
|
app.config['JWT_SECRET_KEY'] = 'super-secret-key' # TODO FIX THIS
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite'
|
|
db.init_app(app)
|
|
JWTManager(app)
|
|
app.register_blueprint(auth_blueprint)
|
|
with app.app_context():
|
|
db.create_all()
|
|
sio.run(app, port=5005)
|