debug room socket conneciton

This commit is contained in:
Sorrel Bri 2019-10-11 22:23:38 -07:00
parent cd1f6a8a44
commit 9d6d482c91
4 changed files with 15 additions and 7 deletions

14
app.py
View file

@ -3,8 +3,6 @@ from database import db, ma
from flask import Flask
from configuration.config import DevelopmentConfig
from flask_bcrypt import Bcrypt
from flask_cors import CORS
from flask_socketio import SocketIO
@ -12,9 +10,17 @@ from flask_socketio import SocketIO
app = Flask(__name__)
bcrypt = Bcrypt(app)
app.config['CORS_HEADERS'] = 'Content-Type'
app.config.from_object(DevelopmentConfig)
# ! Environment Variable
# TODO change to os.getenv('CONFIGURATION')
# TODO export CONFIGURATION='configuration.config.ProductionConfig'
app.config.from_object('configuration.config.DevelopmentConfig')
# ! Environment Variable
# TODO change to os.getenv('ALLOWED_ORIGIN')
# TODO export ALLOWED_ORIGIN= whatever the react server is
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"},

View file

@ -1,5 +1,6 @@
import os
# local db
# ! Environment Variable
DATABASE = 'postgresql://localhost/browser-go'
class BaseConfig:
@ -30,4 +31,4 @@ class ProductionConfig(BaseConfig):
"""Production configuration."""
SECRET_KEY = ''
DEBUG = False
SQLALCHEMY_DATABASE_URI = 'postgresql:///'
SQLALCHEMY_DATABASE_URI = 'postgresql:///'

View file

@ -10,8 +10,6 @@ from websockets.socket import socketio
import configuration.models_mount
from flask_migrate import Migrate
if __name__ == '__main__':
app = create_app()
register_api_endpoints(app)

View file

@ -29,6 +29,9 @@ def handle_connection():
# ! Game Room Messages
def join_room_notice(room):
@socketio.on('connect', namespace=f'/{room}')
def room_socket_mount():
print(f'/{room} socket mounted')
@socketio.on('join room', namespace=f'/{room}')
def connect_room(message):
print(f'connected with ${message}')