From e8df3a55b35890a33dcab577fc2aa749dec0e1ac Mon Sep 17 00:00:00 2001 From: Hailey Date: Mon, 1 Sep 2025 10:26:17 -0700 Subject: [PATCH] nits --- bskylink/src/config.ts | 2 ++ bskylink/src/routes/createShortLink.ts | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/bskylink/src/config.ts b/bskylink/src/config.ts index 13a1991bdb..3f381e4ddb 100644 --- a/bskylink/src/config.ts +++ b/bskylink/src/config.ts @@ -9,6 +9,7 @@ export type ServiceConfig = { port: number version?: string hostnames: string[] + hostnamesSet: Set appHostname: string safelinkEnabled: boolean safelinkPdsUrl?: string @@ -72,6 +73,7 @@ export const envToCfg = (env: Environment): Config => { port: env.port ?? 3000, version: env.version, hostnames: env.hostnames, + hostnamesSet: new Set(env.hostnames), appHostname: env.appHostname ?? 'bsky.app', safelinkEnabled: env.safelinkEnabled ?? false, safelinkPdsUrl: env.safelinkPdsUrl, diff --git a/bskylink/src/routes/createShortLink.ts b/bskylink/src/routes/createShortLink.ts index cc3951525e..629119059f 100644 --- a/bskylink/src/routes/createShortLink.ts +++ b/bskylink/src/routes/createShortLink.ts @@ -84,13 +84,15 @@ const getUrl = (ctx: AppContext, req: Request, id: string) => { return `${baseUrl}/${id}` } const host = req.headers.host ?? '' - const baseUrl = ctx.cfg.service.hostnames.includes(host) + const baseUrl = ctx.cfg.service.hostnamesSet.has(host) ? `https://${host}` : `https://${ctx.cfg.service.hostnames[0]}` return `${baseUrl}/${id}` } const normalizedPathFromParts = (parts: string[]): string => { + // When given ['path1', 'path2', 'te:fg'], output should be + // /path1/path2/te:fg return ( '/' + parts