Update: Cors Origin from Docker Environments

This commit is contained in:
Yûki VACHOT 2022-01-14 01:35:50 +01:00
parent a398b49a98
commit 3615ae8d3b
3 changed files with 9 additions and 4 deletions

View file

@ -1,3 +1,4 @@
from flask import current_app as app
from flask import request, Blueprint from flask import request, Blueprint
from flask_cors import CORS from flask_cors import CORS
from werkzeug.exceptions import HTTPException from werkzeug.exceptions import HTTPException
@ -7,7 +8,10 @@ from .api_functions import db_login, db_register, db_user_update, db_create_log,
from .sessionJWT import create_auth_token, check_auth_token from .sessionJWT import create_auth_token, check_auth_token
bp = Blueprint('myapp', __name__) bp = Blueprint('myapp', __name__)
CORS(bp, supports_credentials=True, origins=['http://127.0.0.1:4200', 'http://localhost:4200']) origin = app.config.get('ALLOW_ORIGIN')
if origin is None:
origin = ['http://127.0.0.1:4200', 'http://localhost:4200']
CORS(bp, supports_credentials=True, origins=origin)
@bp.app_errorhandler(HTTPException) @bp.app_errorhandler(HTTPException)

View file

@ -21,7 +21,7 @@ class Config(object):
} }
SECRET_KEY = os.environ.get('SECRET_KEY', 'default_secret_key') SECRET_KEY = os.environ.get('SECRET_KEY', 'default_secret_key')
ALLOW_ORIGIN = os.environ.get('ALLOW_ORIGIN', '*') ALLOW_ORIGIN = os.environ.get('ALLOW_ORIGIN', None)
class ProductionConfig(Config): class ProductionConfig(Config):

View file

@ -51,8 +51,9 @@ services:
- PYTHONUNBUFFERED=1 - PYTHONUNBUFFERED=1
- DATABASE_URL_USERS=postgresql://flaskaled1:aled1@flaskaled-srv1/flaskaledDb1 - DATABASE_URL_USERS=postgresql://flaskaled1:aled1@flaskaled-srv1/flaskaledDb1
- DATABASE_URL_LOGS=postgresql://flaskaled2:aled2@flaskaled-srv2/flaskaledDb2 - DATABASE_URL_LOGS=postgresql://flaskaled2:aled2@flaskaled-srv2/flaskaledDb2
#SECRET_KEY: default_secret_key - ALLOW_ORIGIN=frontend
#- ALLOW_ORIGIN=frontend - SECRET_KEY=default_secret_key
# frontend: # frontend:
# container_name: frontend # container_name: frontend