The best way to control Claude Code, Codex and more from any computer or phone

main
ts 16 lines 893 Bytes
Raw
1 /**
2 * Origin for absolute social-card URLs (`og:image`, `og:url`, `twitter:image`).
3 *
4 * Builds bake in the `site` config and the deployed worker rewrites those
5 * URLs to each request's host (`rewriteSocialCardHost` in `worker.ts`). The
6 * dev server has no worker in front of it, so in dev the origin comes from the
7 * request URL instead, which lets `astro dev` behind a tunnel unfurl its own
8 * cards. Prerendered pages get no request headers in dev, so the scheme can't
9 * be read from `x-forwarded-proto`; tunnels terminate TLS, so any non-local
10 * host is assumed to be served over https.
11 */
12 export function socialOrigin(site: URL | undefined, url: URL): URL | undefined {
13 if (!import.meta.env.DEV) return site;
14 const local = /^(localhost|127\.|\[::1\]|0\.0\.0\.0|10\.|192\.168\.|100\.)/.test(url.hostname);
15 return new URL(`${local ? url.protocol : "https:"}//${url.host}`);
16 }