forked from R-Gallagher/icarus-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
84 lines (60 loc) · 2.12 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from models.user import UserModel, ProviderModel, AdminModel
from models.specialty import SpecialtyModel
from models.provider_type import ProviderTypeModel
from models.language import LanguageModel
from models.designation import DesignationModel
from models.procedural_wait_time import ProceduralWaitTimeModel
from models.address import AddressModel
from flask import Flask
from extensions import cors, db, jwt, ma, csrf # , tali
from flask_restful import Resource
from os import environ
from flask_migrate import Migrate
# instantiate up here to keep access to app open to other modules
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = environ.get('DATABASE_URL')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
migrate = Migrate(app, db)
# APPLICATION FACTORIES
# as explained here: http://flask.pocoo.org/docs/patterns/appfactories/.
def create_app_production(Configuration):
# adds all the configuration parameters to the flask app
app.config.from_object(Configuration)
# calls the app factory function
register_extensions_production(app)
return app
def register_extensions_production(app):
"""Register Flask extensions."""
from extensions import api
api.init_app(app)
cors.init_app(app, supports_credentials=True)
# need this for true prod
cors.init_app(
app,
resources={
r"/*": {"origins": "https://www.icarusmed.com"}
},
supports_credentials=True)
jwt.init_app(app)
csrf.init_app(app)
return None
def create_app_test(Configuration):
from api import add_resources
from extensions import api, cors, jwt, ma, csrf
from jwt_add import add_jwt
from config import TestingConfig
api.app = app
add_resources(app, api)
add_jwt()
app.config.from_object(TestingConfig)
register_extensions_test(app)
return app
def register_extensions_test(app):
cors.init_app(app, supports_credentials=True)
jwt.init_app(app)
csrf.init_app(app)
return None
if environ.get('DEV_ENV') == 'testing':
from config import TestingConfig
create_app_test(TestingConfig)