]> git.gir.st - subscriptionfeed.git/blob - app/__init__.py
prefer microformat.publishDate
[subscriptionfeed.git] / app / __init__.py
1 import base64
2 import secrets
3 import importlib
4 from flask import Flask
5
6 from .common.common import *
7 from .common.user import init_login
8
9 app = Flask(__name__)
10 app.secret_key = base64.b64decode(cf['frontend'].get('secret_key','')) or \
11 secrets.token_bytes(16) # development fallback; CSRF/cookies won't persist.
12 init_login(app)
13
14 for name in cf['frontend']['modules'].split(','):
15 blueprint = importlib.import_module('.'+name, __name__)
16 app.register_blueprint(blueprint.frontend)
17
18 # TODO: should this go somewhere else?
19 # This error handler logs requests to external apis, and POST data. this makes debugging of api responses easier, as the request can be reconstructed and replayed.
20 from flask import g, request
21 from werkzeug.exceptions import InternalServerError
22 @app.errorhandler(InternalServerError)
23 def log_errors(e):
24 if request.method == "POST":
25 app.logger.error(request.data)
26 if 'api_requests' in g:
27 app.logger.error(g.api_requests)
28 return e
29
30 from .common import anticsrf
31 anticsrf.init(app)
Imprint / Impressum