kopia lustrzana https://github.com/snarfed/bridgy-fed
bridgy-at: integrate XRPC server, testutil, etc
rodzic
b847e72483
commit
ef1c92222b
21
app.py
21
app.py
|
@ -1,9 +1,13 @@
|
||||||
"""Main Flask application."""
|
"""Main Flask application."""
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask_caching import Cache
|
from flask_caching import Cache
|
||||||
import flask_gae_static
|
import flask_gae_static
|
||||||
|
from lexrpc.server import Server
|
||||||
|
from lexrpc.flask_server import init_flask
|
||||||
from oauth_dropins.webutil import (
|
from oauth_dropins.webutil import (
|
||||||
appengine_info,
|
appengine_info,
|
||||||
appengine_config,
|
appengine_config,
|
||||||
|
@ -13,11 +17,14 @@ from oauth_dropins.webutil import (
|
||||||
|
|
||||||
import common
|
import common
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
app_dir = Path(__file__).parent
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__, static_folder=None)
|
app = Flask(__name__, static_folder=None)
|
||||||
app.template_folder = './templates'
|
app.template_folder = './templates'
|
||||||
app.json.compact = False
|
app.json.compact = False
|
||||||
app.config.from_pyfile(Path(__file__).parent / 'config.py')
|
app.config.from_pyfile(app_dir / 'config.py')
|
||||||
app.url_map.converters['regex'] = flask_util.RegexConverter
|
app.url_map.converters['regex'] = flask_util.RegexConverter
|
||||||
app.after_request(flask_util.default_modern_headers)
|
app.after_request(flask_util.default_modern_headers)
|
||||||
app.register_error_handler(Exception, flask_util.handle_exception)
|
app.register_error_handler(Exception, flask_util.handle_exception)
|
||||||
|
@ -34,5 +41,15 @@ cache = Cache(app)
|
||||||
|
|
||||||
util.set_user_agent('Bridgy Fed (https://fed.brid.gy/)')
|
util.set_user_agent('Bridgy Fed (https://fed.brid.gy/)')
|
||||||
|
|
||||||
|
# XRPC server
|
||||||
|
lexicons = []
|
||||||
|
for filename in (app_dir / 'lexicons/app/bsky').glob('**/*.json'):
|
||||||
|
logger.debug(f'Loading lexicon from {filename}')
|
||||||
|
with open(filename) as f:
|
||||||
|
lexicons.append(json.load(f))
|
||||||
|
|
||||||
import activitypub, add_webmention, follow, pages, redirect, render, superfeedr, webfinger, webmention
|
xrpc_server = Server(lexicons, validate=False)
|
||||||
|
init_flask(xrpc_server, app)
|
||||||
|
|
||||||
|
# import all modules to register their Flask handlers
|
||||||
|
import activitypub, add_webmention, follow, pages, redirect, render, superfeedr, webfinger, webmention, xrpc_actor, xrpc_feed, xrpc_graph
|
||||||
|
|
|
@ -29,6 +29,8 @@ class TestCase(unittest.TestCase, testutil.Asserts):
|
||||||
self.ndb_context = ndb_client.context()
|
self.ndb_context = ndb_client.context()
|
||||||
self.ndb_context.__enter__()
|
self.ndb_context.__enter__()
|
||||||
|
|
||||||
|
util.now = lambda **kwargs: testutil.NOW
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.ndb_context.__exit__(None, None, None)
|
self.ndb_context.__exit__(None, None, None)
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
Ładowanie…
Reference in New Issue