add cors
This commit is contained in:
parent
11d3a5af88
commit
e051f3a101
@ -1,2 +1,3 @@
|
||||
FLASK_APP=main.py
|
||||
FLASK_ENV=development
|
||||
FLASK_ENV=development
|
||||
ENABLE_CORS=True
|
@ -2,6 +2,7 @@ import os
|
||||
|
||||
from flask import Flask
|
||||
from flask_migrate import Migrate
|
||||
from flask_cors import CORS
|
||||
|
||||
from .config import config
|
||||
from .dependencies import db, ma
|
||||
@ -16,6 +17,9 @@ def create_app(config_name: str = None) -> Flask:
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(config.get(config_name) or config.get("development"))
|
||||
|
||||
if app.config['ENABLE_CORS']:
|
||||
CORS(app)
|
||||
|
||||
db.init_app(app)
|
||||
ma.init_app(app)
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@ -7,6 +8,7 @@ class Config:
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
SRC_DIR = BASE_DIR / "app"
|
||||
EXCLUDED_DIRS = ["__pycache__", "commands"]
|
||||
ENABLE_CORS = os.environ.get('ENABLE_CORS') or False
|
||||
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
SQLALCHEMY_DATABASE_URI = f'sqlite:///{BASE_DIR / "db.sqlite"}'
|
||||
|
@ -2,6 +2,7 @@ alembic==1.7.7
|
||||
attrs==21.4.0
|
||||
click==8.1.3
|
||||
Flask==2.1.2
|
||||
Flask-Cors==3.0.10
|
||||
flask-marshmallow==0.14.0
|
||||
Flask-Migrate==3.1.0
|
||||
Flask-SQLAlchemy==2.5.1
|
||||
|
Loading…
Reference in New Issue
Block a user