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 flask import Flask
from configuration.config import DevelopmentConfig
from flask_bcrypt import Bcrypt from flask_bcrypt import Bcrypt
from flask_cors import CORS from flask_cors import CORS
from flask_socketio import SocketIO from flask_socketio import SocketIO
@ -12,9 +10,17 @@ from flask_socketio import SocketIO
app = Flask(__name__) 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)
# ! 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") 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"},

View file

@ -1,5 +1,6 @@
import os import os
# local db # local db
# ! Environment Variable
DATABASE = 'postgresql://localhost/browser-go' DATABASE = 'postgresql://localhost/browser-go'
class BaseConfig: class BaseConfig:
@ -30,4 +31,4 @@ class ProductionConfig(BaseConfig):
"""Production configuration.""" """Production configuration."""
SECRET_KEY = '' SECRET_KEY = ''
DEBUG = False 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 import configuration.models_mount
from flask_migrate import Migrate from flask_migrate import Migrate
if __name__ == '__main__': if __name__ == '__main__':
app = create_app() app = create_app()
register_api_endpoints(app) register_api_endpoints(app)

View file

@ -29,6 +29,9 @@ def handle_connection():
# ! Game Room Messages # ! Game Room Messages
def join_room_notice(room): 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}') @socketio.on('join room', namespace=f'/{room}')
def connect_room(message): def connect_room(message):
print(f'connected with ${message}') print(f'connected with ${message}')