-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
51 lines (38 loc) · 1.41 KB
/
app.py
File metadata and controls
51 lines (38 loc) · 1.41 KB
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
from flask import Flask, app
from flask_restful import Api
from flask_mongoengine import MongoEngine
from flask_jwt_extended import JWTManager
from config.settings import *
from api.routes import create_routes
def get_flask_app(config: dict = None, *args, **kwargs) -> app.Flask:
"""
Initializes Flask app with given configuration.
:param config: Optional configuration dictionary
:return: app.Flask
"""
# init flask
flask_app = Flask(__name__)
# configure app
if config is not None:
flask_app.config.update(config)
flask_app.config.update(kwargs)
# init mongo
flask_app.config["MONGODB_SETTINGS"] = {
'db': 'sloovi_db', 'host': MONGODB_URI}
# load config variables for jwt from settings.py
flask_app.config['PROPAGATE_EXCEPTIONS'] = PROPAGATE_EXCEPTIONS
flask_app.config['JWT_SECRET_KEY'] = JWT_SECRET_KEY
flask_app.config['JWT_COOKIE_SECURE'] = JWT_COOKIE_SECURE
flask_app.config['JWT_ACCESS_TOKEN_EXPIRES'] = JWT_ACCESS_TOKEN_EXPIRES
flask_app.config['JWT_REFRESH_TOKEN_EXPIRES'] = JWT_REFRESH_TOKEN_EXPIRES
# init api and routes
create_routes(Api(app=flask_app))
# init mongoengine
MongoEngine(app=flask_app)
# init jwt manager
JWTManager(app=flask_app)
return flask_app
if __name__ == '__main__' and DEBUG:
# Main entry point when run in stand-alone mode.
app = get_flask_app()
app.run(debug=DEBUG)