-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
68 lines (59 loc) · 1.84 KB
/
app.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
import os
import warnings
import pydevd
from apispec import APISpec
from apispec.ext.marshmallow import MarshmallowPlugin
from flask import Flask
from werkzeug.utils import import_string
from admin import admin
from config import TestingConfig
from core.extensions import migrate, ma, mail, docs
from errors import error_bp
from v1 import v1_bp
from v1.api_docs import add_docs
from v1.routes import *
def create_app(config="config.DevelopmentConfig"):
if os.environ.get("DEBUG") == "true":
pydevd.settrace(
"host.docker.internal",
port=12345,
stdoutToServer=True,
stderrToServer=True,
suspend=False,
)
app = Flask(__name__, template_folder="templates/")
cfg = import_string(config)()
app.config.from_object(cfg)
if not isinstance(cfg, TestingConfig):
mail_settings = {
"MAIL_SERVER": "smtp.gmail.com",
"MAIL_PORT": 465,
"MAIL_USE_TLS": False,
"MAIL_USE_SSL": True,
"MAIL_USERNAME": os.environ.get("MAIL_USERNAME"),
"MAIL_PASSWORD": os.environ.get("MAIL_PASSWORD"),
}
app.config.update(mail_settings)
mail.init_app(app)
db.init_app(app)
migrate.init_app(app, db)
ma.init_app(app)
jwt.init_app(app)
admin.init_app(app)
docs.init_app(app)
app.config.update(
{
"APISPEC_SPEC": APISpec(
title="InternsAID",
version="v1",
openapi_version="3.0.1",
plugins=[MarshmallowPlugin()],
),
"APISPEC_SWAGGER_URL": "/swagger/",
}
)
warnings.filterwarnings("ignore", message="Multiple schemas resolved to the name")
app.register_blueprint(error_bp)
app.register_blueprint(v1_bp, url_prefix="/api/v1")
add_docs(cfg)
return app