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
|
import os
import logging
import logging.handlers
from datetime import timedelta
logger = logging.getLogger("")
logger.setLevel(logging.DEBUG)
handler = logging.handlers.RotatingFileHandler("flask.log",
maxBytes=3000000, backupCount=2)
formatter = logging.Formatter(
'[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logging.getLogger().addHandler(logging.StreamHandler())
from flask import Flask, Blueprint, send_from_directory, request
from app.sql.common import db, connection_url
from app.utils.auth_utils import setup_jwt
from app.settings import app_cfg
from app.controllers.annotation_controller import AnnotationView
from app.controllers.paragraph_controller import ParagraphView
from app.controllers.upload_controller import UploadView
from app.controllers.media_controller import MediaView
from app.controllers.episode_controller import EpisodeView
from app.controllers.project_controller import ProjectView
from app.controllers.venue_controller import VenueView
from app.controllers.user_controller import UserView
from app.controllers.auth_controller import AuthView
def create_app(script_info=None):
"""
functional pattern for creating the flask app
"""
logging.debug("Starting Flask app...")
# print(app_cfg.SERVER_NAME)
app = Flask(__name__, static_folder=app_cfg.DIR_STATIC, static_url_path='/static')
app.config['SQLALCHEMY_DATABASE_URI'] = connection_url
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SERVER_NAME'] = app_cfg.SERVER_NAME
app.config['JWT_SECRET_KEY'] = app_cfg.TOKEN_SECRET
app.config['JWT_AUTH_URL_RULE'] = '/api/v1/auth/login'
app.config['JWT_ACCESS_TOKEN_EXPIRES'] = False # timedelta(days=365 * 10)
app.url_map.strict_slashes = False
db.init_app(app)
setup_jwt(app)
AnnotationView.register(app, route_prefix='/api/v1/')
ParagraphView.register(app, route_prefix='/api/v1/')
UploadView.register(app, route_prefix='/api/v1/')
MediaView.register(app, route_prefix='/api/v1/')
EpisodeView.register(app, route_prefix='/api/v1/')
ProjectView.register(app, route_prefix='/api/v1/')
VenueView.register(app, route_prefix='/api/v1/')
UserView.register(app, route_prefix='/api/v1/')
AuthView.register(app, route_prefix='/api/v1/')
index_html = 'index.html'
@app.errorhandler(404)
def page_not_found(e):
return app.send_static_file(index_html), 200
# path = os.path.join(os.path.dirname(__file__), './static/index.html')
# with open(path, "r") as f:
# return f.read(), 200
@app.route('/', methods=['GET'])
def index():
return app.send_static_file('index.html')
@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static/img/'),
'favicon.ico',mimetype='image/vnd.microsoft.icon')
@app.shell_context_processor
def shell_context():
return { 'app': app, 'db': db }
return app
|