Commit 30bc766
committed
fix(og): derive og:image origin from incoming request, not env vars
On Netlify deploy previews, og:image was rendering as
`https://tanstack.com/api/og/<lib>.png` — pointing at production rather
than the preview origin — making the new takumi binary fix impossible
to validate from the preview HTML.
The previous attempt read `process.env.DEPLOY_PRIME_URL` etc. inside the
SSR function, but those variables turn out to be unreliable (or absent)
in our bundled function context, so the chain fell through to `URL`,
which is the production hostname even on a deploy preview.
Use `getRequest()` from `@tanstack/react-start/server` instead — the
incoming Request URL is the source of truth for which origin served
this page, and it always matches the deploy that's about to fetch the
og:image. Verified locally that og:image now renders as
`http://localhost:3000/api/og/<lib>.png`.
- vite.config.ts: allow `src/utils/og.ts` to import
`@tanstack/react-start/server`. Uses are gated by `import.meta.env.SSR`
so the import is tree-shaken from the client bundle; allowlisting
just lets the static import through the protection check.
- og.ts: prefer `new URL(getRequest().url).origin` for the SSR origin,
with the env-var chain kept as a fallback for non-request contexts.1 parent ccd4a68 commit 30bc766
2 files changed
Lines changed: 19 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | | - | |
24 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
25 | 29 | | |
26 | 30 | | |
27 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
28 | 39 | | |
29 | 40 | | |
30 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
229 | | - | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
230 | 235 | | |
231 | 236 | | |
232 | 237 | | |
| |||
0 commit comments