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