diff --git a/app.py b/app.py index 797af7d..2a0a63d 100644 --- a/app.py +++ b/app.py @@ -1,9 +1,13 @@ """Main Flask application.""" +import json +import logging from pathlib import Path from flask import Flask from flask_caching import Cache import flask_gae_static +from lexrpc.server import Server +from lexrpc.flask_server import init_flask from oauth_dropins.webutil import ( appengine_info, appengine_config, @@ -13,11 +17,14 @@ from oauth_dropins.webutil import ( import common +logger = logging.getLogger(__name__) +app_dir = Path(__file__).parent + app = Flask(__name__, static_folder=None) app.template_folder = './templates' 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.after_request(flask_util.default_modern_headers) 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/)') +# 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 diff --git a/tests/testutil.py b/tests/testutil.py index 8ce72f7..ccb5337 100644 --- a/tests/testutil.py +++ b/tests/testutil.py @@ -29,6 +29,8 @@ class TestCase(unittest.TestCase, testutil.Asserts): self.ndb_context = ndb_client.context() self.ndb_context.__enter__() + util.now = lambda **kwargs: testutil.NOW + def tearDown(self): self.ndb_context.__exit__(None, None, None) super().tearDown()