From 0e6967b34a3b81ece18e622b787a19e18c09789e Mon Sep 17 00:00:00 2001 From: Alynna Trypnotk Date: Tue, 30 Oct 2018 22:35:04 +0000 Subject: [PATCH] Added options to change the default listen address and port. Added default page that explains how to use the relay. Added note option to add information about the relay content and/or TOS. --- relay.yaml.example | 9 ++++++++- relay/__init__.py | 2 +- relay/__main__.py | 16 +++++++++++----- relay/default.py | 30 ++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 relay/default.py diff --git a/relay.yaml.example b/relay.yaml.example index 3445136..fdcfb09 100644 --- a/relay.yaml.example +++ b/relay.yaml.example @@ -2,8 +2,15 @@ # you probably shouldn't change it, but you can if you want. db: relay.jsonld +# Listener +listen: 0.0.0.0 +port: 8080 + +# Note +note: "Make a note about your instance here." + # this section is for ActivityPub ap: # this is used for generating activitypub messages, as well as instructions for # linking AP identities. it should be an SSL-enabled domain reachable by https. - host: 'relay.pleroma.site' + host: 'relay.kitsunet.net' diff --git a/relay/__init__.py b/relay/__init__.py index 8c55bbf..cf12bd0 100644 --- a/relay/__init__.py +++ b/relay/__init__.py @@ -26,4 +26,4 @@ app = aiohttp.web.Application(middlewares=[ from . import database from . import actor from . import webfinger - +from . import default diff --git a/relay/__main__.py b/relay/__main__.py index 3b2caea..0bb2f7b 100644 --- a/relay/__main__.py +++ b/relay/__main__.py @@ -2,19 +2,25 @@ import asyncio import aiohttp.web import logging -from . import app - +from . import app, CONFIG async def start_webserver(): runner = aiohttp.web.AppRunner(app) await runner.setup() + try: + listen = CONFIG['listen'] + except: + listen = 'localhost' + try: + port = CONFIG['port'] + except: + port = 8080 - logging.info('Starting webserver at localhost:8080') + logging.info('Starting webserver at {listen}:{port}'.format(listen=listen,port=port)) - site = aiohttp.web.TCPSite(runner, 'localhost', 8080) + site = aiohttp.web.TCPSite(runner, listen, port) await site.start() - def main(): loop = asyncio.get_event_loop() asyncio.ensure_future(start_webserver()) diff --git a/relay/default.py b/relay/default.py new file mode 100644 index 0000000..295d3e4 --- /dev/null +++ b/relay/default.py @@ -0,0 +1,30 @@ +import aiohttp.web +from . import app, CONFIG + +host = CONFIG['ap']['host'] +host = CONFIG['note'] + +async def default(request): + return aiohttp.web.Response( + status=200, + content_type="text/html", + charset="utf-8", + text=""" + + ActivityPub Relay at {host} + + + +

This is an Activity Relay for fediverse instances.

+

{note}

+

For Mastodon instances, you may subscribe to this relay with the address: https://{host}/inbox

+

For Pleroma and other instances, you may subscribe to this relay with the address: https://{host}/actor

+

To host your own relay, you may download the code at this address: https://git.pleroma.social/pleroma/relay

+ + +""".format(host=host)) + +app.router.add_get('/', default)