This commit is contained in:
Hailey
2025-09-01 10:26:17 -07:00
parent b543f5790c
commit e8df3a55b3
2 changed files with 5 additions and 1 deletions
+2
View File
@@ -9,6 +9,7 @@ export type ServiceConfig = {
port: number
version?: string
hostnames: string[]
hostnamesSet: Set<string>
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,
+3 -1
View File
@@ -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