Merge pull request #18 from sorrelbri/sj-configuration
sj configuration
This commit is contained in:
commit
ce0c0bf98f
4 changed files with 16 additions and 10 deletions
18
app.py
18
app.py
|
@ -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,13 +10,19 @@ 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)
|
|
||||||
socketio = SocketIO(app, cors_allowed_origins="http://localhost:3000")
|
# ! Environment Variable
|
||||||
# cors_allowed_origins="http://localhost:3000"
|
# TODO export CONFIGURATION_OBJECT='configuration.config.ProductionConfig'
|
||||||
|
app.config.from_object(os.getenv('CONFIGURATION_OBJECT'))
|
||||||
|
|
||||||
|
# ! Environment Variable
|
||||||
|
# TODO export ALLOWED_ORIGIN= whatever the react server is
|
||||||
|
socketio = SocketIO(app, cors_allowed_origins=os.getenv('ALLOWED_ORIGIN'))
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
CORS(app, resources={
|
CORS(app, resources={
|
||||||
r"/api/*": {"origins": "http://localhost:3000"},
|
r"/api/*": {"origins": os.getenv('ALLOWED_ORIGIN')},
|
||||||
r"/auth/*": {"origins": "http://localhost:3000"},
|
r"/auth/*": {"origins": os.getenv('ALLOWED_ORIGIN')},
|
||||||
})
|
})
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
ma.init_app(app)
|
ma.init_app(app)
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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}')
|
||||||
|
|
Loading…
Reference in a new issue