2021-07-07 15:07:20 +00:00
|
|
|
"""Main Flask application."""
|
2021-07-11 20:39:19 +00:00
|
|
|
import logging
|
|
|
|
|
2021-07-07 15:07:20 +00:00
|
|
|
from flask import Flask
|
|
|
|
from flask_caching import Cache
|
2021-07-11 20:39:19 +00:00
|
|
|
from werkzeug.exceptions import HTTPException
|
|
|
|
|
2021-07-07 15:07:20 +00:00
|
|
|
from oauth_dropins.webutil import appengine_info, appengine_config, handlers, util
|
2019-12-26 06:20:57 +00:00
|
|
|
|
2021-07-07 15:07:20 +00:00
|
|
|
app = Flask('bridgy-fed')
|
|
|
|
app.template_folder = './templates'
|
|
|
|
app.config.from_mapping(
|
|
|
|
ENV='development' if appengine_info.DEBUG else 'PRODUCTION',
|
|
|
|
CACHE_TYPE='SimpleCache',
|
|
|
|
SECRET_KEY=util.read('flask_secret_key'),
|
2021-07-08 04:02:13 +00:00
|
|
|
JSONIFY_PRETTYPRINT_REGULAR=True,
|
2021-07-07 15:07:20 +00:00
|
|
|
)
|
|
|
|
app.wsgi_app = handlers.ndb_context_middleware(
|
|
|
|
app.wsgi_app, client=appengine_config.ndb_client)
|
2019-12-26 06:20:57 +00:00
|
|
|
|
2021-07-07 15:07:20 +00:00
|
|
|
cache = Cache(app)
|
2019-12-26 06:20:57 +00:00
|
|
|
|
2021-07-11 15:48:28 +00:00
|
|
|
@app.errorhandler(Exception)
|
|
|
|
def handle_exception(e):
|
2021-07-11 20:39:19 +00:00
|
|
|
"""A Flask error handler that propagates HTTP exceptions into the response."""
|
|
|
|
code, body = util.interpret_http_exception(e)
|
|
|
|
if code:
|
|
|
|
return ((f'Upstream server request failed: {e}' if code in ('502', '504')
|
|
|
|
else f'HTTP Error {code}: {body}'),
|
|
|
|
int(code))
|
|
|
|
|
|
|
|
logging.error(f'{e.__class__}: {e}')
|
|
|
|
if isinstance(e, HTTPException):
|
|
|
|
return e
|
|
|
|
else:
|
|
|
|
raise e
|
2021-07-11 15:48:28 +00:00
|
|
|
|
2021-07-07 15:07:20 +00:00
|
|
|
import activitypub, add_webmention, logs, redirect, render, salmon, superfeedr, webfinger, webmention
|