-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
75 lines (62 loc) · 1.8 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
from flask import Flask
from flask_cors import CORS
from flask_jwt_extended import JWTManager
from flask_mail import Mail
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_socketio import SocketIO
from dotenv import load_dotenv
load_dotenv()
jwt = JWTManager()
mail = Mail()
db = SQLAlchemy()
migrate = Migrate()
socketio = SocketIO()
def create_app(testing=False):
app = Flask(__name__)
# Configuration Options
config = {
"SECRET_KEY": bytes.fromhex(os.getenv("SECRET_KEY")),
"SQLALCHEMY_DATABASE_URI": os.getenv("SQLALCHEMY_DATABASE_URI"),
"SQLALCHEMY_TRACK_MODIFICATIONS": os.getenv("SQLALCHEMY_TRACK_MODIFICATIONS").lower() in ("true", "1"),
"MAIL_SERVER": os.getenv("MAIL_SERVER"),
"MAIL_PORT": os.getenv("MAIL_PORT"),
"MAIL_USE_TLS": os.getenv("MAIL_USE_TLS").lower() in ("true", "1"),
"MAIL_USERNAME": os.getenv("MAIL_USERNAME"),
"MAIL_PASSWORD": os.getenv("MAIL_PASSWORD")
}
if testing:
pass
else:
app.config.update(config)
from .controllers import blueprints
for bp in blueprints:
bp.setup(app)
jwt.init_app(app)
mail.init_app(app)
db.init_app(app)
migrate.init_app(app, db)
socketio.init_app(
app,
namespaces=[
'/notifications',
],
cors_allowed_origins=os.getenv("CORS_ALLOWED_ORIGINS")
)
with app.app_context():
if testing:
db.drop_all()
db.create_all()
db.session.commit()
CORS(
app,
resources={
r"/*": {
"origins": os.getenv("CORS_ALLOWED_ORIGINS")
}
}
)
from .exception_handler import handle_exception
app.errorhandler(Exception)(handle_exception)
return app