From 9d6d482c919c44d08fcf74ccddd8694acb35316d Mon Sep 17 00:00:00 2001 From: Sorrel Bri Date: Fri, 11 Oct 2019 22:23:38 -0700 Subject: [PATCH] debug room socket conneciton --- app.py | 14 ++++++++++---- configuration/config.py | 3 ++- server.py | 2 -- websockets/socket.py | 3 +++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index fe753db..5b00bf9 100644 --- a/app.py +++ b/app.py @@ -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"}, diff --git a/configuration/config.py b/configuration/config.py index 4912a7b..efdd88e 100644 --- a/configuration/config.py +++ b/configuration/config.py @@ -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:///' \ No newline at end of file + SQLALCHEMY_DATABASE_URI = 'postgresql:///' diff --git a/server.py b/server.py index 226bf96..a67d0ec 100644 --- a/server.py +++ b/server.py @@ -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) diff --git a/websockets/socket.py b/websockets/socket.py index 515cb47..d2a2d11 100644 --- a/websockets/socket.py +++ b/websockets/socket.py @@ -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}')