Skip to content

Commit

Permalink
prod vs local setup, redirect home page to bsky.app profile
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Oct 21, 2024
1 parent 4b7be47 commit 87be65d
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import arroba.util
from cryptography.hazmat.primitives import serialization
from flask import Flask
from flask import Flask, redirect
from google.cloud import error_reporting
import google.cloud.logging
import lexrpc.flask_server
Expand All @@ -45,14 +45,15 @@

# https://cloud.google.com/appengine/docs/flexible/python/runtime#environment_variables
PROD = 'GAE_INSTANCE' in os.environ
if PROD:
logging_client = google.cloud.logging.Client()
logging_client.setup_logging(log_level=logging.DEBUG)
error_reporting_client = error_reporting.Client()
else:
logging.basicConfig()

logging_client = google.cloud.logging.Client()
logging_client.setup_logging(log_level=logging.DEBUG)
logger = logging.getLogger(__name__)

if not PROD:
error_reporting_client = error_reporting.Client()

logger.info('Loading #atproto_label private key from privkey.atproto_label.pem')
with open('privkey.atproto_label.pem', 'rb') as f:
privkey = serialization.load_pem_private_key(f.read(), password=None)
Expand All @@ -69,6 +70,12 @@
app.config.from_pyfile(app_dir / 'config.py')


@app.route('/')
def home_page():
"""Redirect to bsky.app labeler profile."""
return redirect('https://bsky.app/profile/self-labeler.snarfed.org', code=302)


# ATProto XRPC server
xrpc_server = lexrpc.server.Server(validate=True)
lexrpc.flask_server.init_flask(xrpc_server, app)
Expand Down Expand Up @@ -120,6 +127,10 @@ def jetstream():
except simple_websocket.ConnectionClosed as cc:
logger.info(f'reconnecting after jetstream disconnect: {cc}')

except BaseException as err:
if PROD:
error_reporting_client.report_error(msg=None, exception=True)


@xrpc_server.method('com.atproto.label.subscribeLabels')
def subscribe_labels(cursor=None):
Expand Down

0 comments on commit 87be65d

Please sign in to comment.