-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
73 lines (57 loc) · 1.97 KB
/
main.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
import os
from flask import Flask
from flask_debugtoolbar import DebugToolbarExtension
from flask_jwt_extended import JWTManager
from api_specs import spec
def create_app(test_config=None) -> Flask:
"""
Per the App Factory pattern, this creates a new instance of the BlockPy app.
:param test_config: 'testing' for unit tests, or a specific config object.
:return:
"""
# create and configure the app
app = Flask('blockpy', instance_relative_config=True, static_folder=None)
# load the test config if passed in
if test_config is not None:
if test_config == 'testing':
app.config.from_object('config.TestConfig')
else:
app.config.from_mapping(test_config)
elif app.env == 'production':
app.config.from_object('config.ProductionConfig')
elif app.env == 'development':
app.config.from_object('config.DevelopmentConfig')
app.config.from_pyfile('configuration.py')
# Additional settings being overridden here
app.config['TEMPLATES_AUTO_RELOAD'] = True
# Set up the API Spec information
# TODO: Consider moving this to a static file
app.config.update({'APISPEC_SPEC': spec})
# Ensure the instance folder exists
try:
os.makedirs(app.instance_path)
except OSError:
pass
# Load up the database
from models import init_database
init_database(app)
# Turn on Debug Toolbar
DebugToolbarExtension(app)
# Set Up JWT
jwt = JWTManager(app)
# Modify Jinja2
# from controllers.jinja_filters import setup_jinja_filters
# setup_jinja_filters(app)
# Logging
# from controllers.interaction_logger import setup_logging
# setup_logging(app)
# Assets
# from controllers.assets import assets
# Email
# from flask_mail import Mail
# mail = Mail(app)
# Set up all the endpoints
with app.app_context():
from controllers import create_blueprints
create_blueprints(app)
return app