Skip to content

Commit 4d7cc5d

Browse files
author
Alvaro Farias
committed
🏗️ update app implement application factory pattern
1 parent f5c3ae2 commit 4d7cc5d

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

app/__init__.py

+33-10
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,39 @@
44
from config.application import config
55
from app.http.controllers.api.PredictionController import PredictionController
66

7-
app = Flask(__name__)
8-
app.config.from_mapping(
9-
ENV=config['env'],
10-
DEBUG=config['debug'],
11-
SECRET_KEY=config['key']
12-
)
7+
# -------------------------------------------------------------------------
8+
# Extension Objects
9+
# -------------------------------------------------------------------------
10+
#
11+
# Initialize extensions accessible to any part of our app
12+
api = Api()
1313

14-
CORS(app, origins=config['origins'])
1514

16-
api = Api(app)
17-
api.add_resource(PredictionController, '/prediction')
15+
def create_app() -> Flask:
16+
"""
17+
Create The Application
18+
The first thing we will do is create a new application instance
19+
which serves as the "glue" for all the components of the api.
20+
:return: Flask
21+
"""
22+
app = Flask(__name__)
1823

19-
__version__ = "0.1"
24+
app.config.from_mapping(
25+
ENV=config['env'],
26+
DEBUG=config['debug'],
27+
SECRET_KEY=config['key']
28+
)
29+
30+
CORS(app, origins=config['origins'])
31+
32+
# Initialize Extensions
33+
api.init_app(app)
34+
35+
with app.app_context():
36+
# Register resources
37+
api.add_resource(PredictionController, '/prediction')
38+
39+
return app
40+
41+
42+
__version__ = "0.1.0"

0 commit comments

Comments
 (0)