-
Notifications
You must be signed in to change notification settings - Fork 49
/
run.py
72 lines (53 loc) · 1.66 KB
/
run.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
import firebase_admin
from dotenv import load_dotenv, find_dotenv
from firebase_admin import credentials
from flask import Flask
from flask_cors import CORS
from os import environ
from app.api.controllers import api
from app.database.sqlalchemy_extension import db
from config import LocalConfig, get_env_config
cors = CORS()
def create_app(config_env=None) -> Flask:
app = Flask(__name__)
if config_env:
app.config.from_object(config_env)
else:
app.config["SQLALCHEMY_DATABASE_URI"] = LocalConfig.SQLALCHEMY_DATABASE_URI
app.url_map.strict_slashes = False
load_dotenv(find_dotenv())
""" Download service file from firebase and put it in project root directory """
cred = credentials.Certificate("google-credentials.json")
firebase_admin.initialize_app(cred)
mail_settings = {
"MAIL_SERVER": "smtp.gmail.com",
"MAIL_PORT": 465,
"MAIL_USE_TLS": False,
"MAIL_USE_SSL": True,
"MAIL_USERNAME": environ.get("EMAIL_USER"),
"MAIL_PASSWORD": environ.get("EMAIL_PASS"),
}
cors.init_app(
app,
resources={
r"*": {
"origins": [
"http://localhost:3000",
"https://anitab-org.github.io",
]
}
},
)
app.config.update(mail_settings)
api.init_app(app)
db.init_app(app)
from app.utils.mail_extension import mail
mail.init_app(app)
return app
config, port = get_env_config().values()
application = create_app(config)
@application.before_first_request
def create_tables():
db.create_all()
if __name__ == "__main__":
application.run(port=port)