@clerk/shared
Version:
Internal package utils used by the Clerk SDKs
1 lines • 2.23 kB
Source Map (JSON)
{"version":3,"sources":["../src/proxy.ts"],"sourcesContent":["import { deprecated } from './deprecated';\n\nexport function isValidProxyUrl(key: string | undefined) {\n if (!key) {\n return true;\n }\n\n return isHttpOrHttps(key) || isProxyUrlRelative(key);\n}\n\nexport function isHttpOrHttps(key: string | undefined) {\n return /^http(s)?:\\/\\//.test(key || '');\n}\n\nexport function isProxyUrlRelative(key: string) {\n return key.startsWith('/');\n}\n\nexport function proxyUrlToAbsoluteURL(url: string | undefined): string {\n if (!url) {\n return '';\n }\n return isProxyUrlRelative(url) ? new URL(url, window.location.origin).toString() : url;\n}\n\n/**\n * @deprecated Use `buildRequestUrl` from @clerk/backend\n */\nexport function getRequestUrl({ request, relativePath }: { request: Request; relativePath?: string }): URL {\n deprecated('getRequestUrl', 'Use `buildRequestUrl` from @clerk/backend instead.');\n const { headers, url: initialUrl } = request;\n const url = new URL(initialUrl);\n const host = headers.get('X-Forwarded-Host') ?? headers.get('host') ?? (headers as any)['host'] ?? url.host;\n\n // X-Forwarded-Proto could be 'https, http'\n let protocol =\n (headers.get('X-Forwarded-Proto') ?? (headers as any)['X-Forwarded-Proto'])?.split(',')[0] ?? url.protocol;\n protocol = protocol.replace(/[:/]/, '');\n\n return new URL(relativePath || url.pathname, `${protocol}://${host}`);\n}\n"],"mappings":";;;;;AAEO,SAAS,gBAAgB,KAAyB;AACvD,MAAI,CAAC,KAAK;AACR,WAAO;AAAA,EACT;AAEA,SAAO,cAAc,GAAG,KAAK,mBAAmB,GAAG;AACrD;AAEO,SAAS,cAAc,KAAyB;AACrD,SAAO,iBAAiB,KAAK,OAAO,EAAE;AACxC;AAEO,SAAS,mBAAmB,KAAa;AAC9C,SAAO,IAAI,WAAW,GAAG;AAC3B;AAEO,SAAS,sBAAsB,KAAiC;AACrE,MAAI,CAAC,KAAK;AACR,WAAO;AAAA,EACT;AACA,SAAO,mBAAmB,GAAG,IAAI,IAAI,IAAI,KAAK,OAAO,SAAS,MAAM,EAAE,SAAS,IAAI;AACrF;AAKO,SAAS,cAAc,EAAE,SAAS,aAAa,GAAqD;AACzG,aAAW,iBAAiB,oDAAoD;AAChF,QAAM,EAAE,SAAS,KAAK,WAAW,IAAI;AACrC,QAAM,MAAM,IAAI,IAAI,UAAU;AAC9B,QAAM,OAAO,QAAQ,IAAI,kBAAkB,KAAK,QAAQ,IAAI,MAAM,KAAM,QAAgB,MAAM,KAAK,IAAI;AAGvG,MAAI,YACD,QAAQ,IAAI,mBAAmB,KAAM,QAAgB,mBAAmB,IAAI,MAAM,GAAG,EAAE,CAAC,KAAK,IAAI;AACpG,aAAW,SAAS,QAAQ,QAAQ,EAAE;AAEtC,SAAO,IAAI,IAAI,gBAAgB,IAAI,UAAU,GAAG,QAAQ,MAAM,IAAI,EAAE;AACtE;","names":[]}