establish initial socket connection
This commit is contained in:
parent
44d365199f
commit
73a7373478
4 changed files with 20 additions and 6 deletions
12
api/api.py
12
api/api.py
|
@ -1,5 +1,7 @@
|
|||
from flask import Blueprint, request, jsonify, session
|
||||
from .users.user_endpoint import UserEndpoint
|
||||
from app import socketio
|
||||
from flask_socketio import emit
|
||||
|
||||
api = Blueprint('api', __name__, url_prefix='/api')
|
||||
|
||||
|
@ -15,3 +17,13 @@ def api_users():
|
|||
@api.route('/user')
|
||||
def api_user():
|
||||
return jsonify(UserEndpoint.user())
|
||||
|
||||
@socketio.on('connect')
|
||||
def handle_connection():
|
||||
print('connected')
|
||||
socketio.emit('connect', payload={'data':'connection'})
|
||||
|
||||
@socketio.on('message')
|
||||
def handle_message(message):
|
||||
print(message)
|
||||
emit('message return', {'data':'a message was sent'})
|
6
app.py
6
app.py
|
@ -13,12 +13,12 @@ app = Flask(__name__)
|
|||
bcrypt = Bcrypt(app)
|
||||
app.config['CORS_HEADERS'] = 'Content-Type'
|
||||
app.config.from_object(DevelopmentConfig)
|
||||
socketio = SocketIO(app)
|
||||
|
||||
socketio = SocketIO(app, cors_allowed_origins="http://localhost:3000")
|
||||
# cors_allowed_origins="http://localhost:3000"
|
||||
def create_app():
|
||||
CORS(app, resources={
|
||||
r"/api/*": {"origins": "http://localhost:3000"},
|
||||
r"/auth/*": {"origins": "http://localhost:3000"}
|
||||
r"/auth/*": {"origins": "http://localhost:3000"},
|
||||
})
|
||||
db.init_app(app)
|
||||
ma.init_app(app)
|
||||
|
|
|
@ -14,7 +14,7 @@ class DevelopmentConfig(BaseConfig):
|
|||
DEBUG = True
|
||||
BCRYPT_LOG_ROUNDS = 4
|
||||
SQLALCHEMY_DATABASE_URI = DATABASE
|
||||
PORT = 8000
|
||||
PORT = 5000
|
||||
|
||||
|
||||
class TestingConfig(BaseConfig):
|
||||
|
|
|
@ -3,6 +3,8 @@ astroid==2.3.1
|
|||
bcrypt==3.1.7
|
||||
cffi==1.12.3
|
||||
Click==7.0
|
||||
dnspython==1.16.0
|
||||
eventlet==0.25.1
|
||||
Flask==1.1.1
|
||||
Flask-Bcrypt==0.7.1
|
||||
Flask-Cors==3.0.8
|
||||
|
@ -12,7 +14,6 @@ Flask-Script==2.0.6
|
|||
Flask-SocketIO==4.2.1
|
||||
Flask-SQLAlchemy==2.4.1
|
||||
Flask-Testing==0.7.1
|
||||
gevent==1.4.0
|
||||
greenlet==0.4.15
|
||||
isort==4.3.21
|
||||
itsdangerous==1.1.0
|
||||
|
@ -23,6 +24,7 @@ MarkupSafe==1.1.1
|
|||
marshmallow==3.2.0
|
||||
marshmallow-sqlalchemy==0.19.0
|
||||
mccabe==0.6.1
|
||||
monotonic==1.5
|
||||
numpy==1.17.2
|
||||
psycopg2==2.8.3
|
||||
pycparser==2.19
|
||||
|
|
Loading…
Reference in a new issue