From e8d0652f63c5280886637d6d92ebc0b39d550d24 Mon Sep 17 00:00:00 2001 From: rafael Date: Mon, 6 Jan 2025 19:39:10 -0300 Subject: [PATCH] Special-case cfgured appview DID and URL on proxy --- packages/dev-env/src/bsky.ts | 14 ++++++++++++++ packages/pds/src/pipethrough.ts | 10 +++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/dev-env/src/bsky.ts b/packages/dev-env/src/bsky.ts index fd61bb7c9c0..b20191257c4 100644 --- a/packages/dev-env/src/bsky.ts +++ b/packages/dev-env/src/bsky.ts @@ -34,6 +34,20 @@ export class TestBsky { signer: serviceKeypair, }) + const endpoint = `http://localhost:${port}` + + await plcClient.updateData(serverDid, serviceKeypair, (x) => { + x.services['bsky_notif'] = { + type: 'BskyNotificationService', + endpoint, + } + x.services['bsky_appview'] = { + type: 'BskyAppView', + endpoint, + } + return x + }) + // shared across server, ingester, and indexer in order to share pool, avoid too many pg connections. const db = new bsky.Database({ url: cfg.dbPostgresUrl, diff --git a/packages/pds/src/pipethrough.ts b/packages/pds/src/pipethrough.ts index d96b33ac8c2..c54cf81ea5a 100644 --- a/packages/pds/src/pipethrough.ts +++ b/packages/pds/src/pipethrough.ts @@ -224,7 +224,7 @@ export async function parseProxyInfo( export const parseProxyHeader = async ( // Using subset of AppContext for testing purposes - ctx: Pick, + ctx: Pick, proxyTo: string, ): Promise<{ did: string; url: string }> => { // /!\ Hot path @@ -261,6 +261,14 @@ export const parseProxyHeader = async ( throw new InvalidRequestError('could not resolve proxy did service url') } + // Special case a configured appview, while still proxying correctly any other appview + if ( + ctx.cfg.bskyAppView && + proxyTo === `${ctx.cfg.bskyAppView.did}#bsky_appview` + ) { + return { did, url: ctx.cfg.bskyAppView.url } + } + return { did, url } }