Root cause for all-blank-placeholders on the food-app brief: Node's native fetch (used by the Nitro dev server's image-search endpoint) ignores the system proxy by default. On machines that route outbound HTTPS through a local proxy (clash / mihomo / corporate gateway — mine sits at 127.0.0.1:7897), every Openverse + Wikimedia call from the server silently ECONNREFUSEDs. The endpoint's catch block returns `null` for Openverse → falls back to Wikimedia → that ECONNREFUSEDs too → returns `[]`. Browser shows zero filled images. Direct curl from the same machine uses HTTPS_PROXY automatically, which is why a manual API check (e.g. `curl https://api.openverse.org/...`) returned 240 results for "salmon sushi" while `/api/ai/image-search?query=salmon%20sushi` returned `{results:[]}`. `apps/web/server/utils/proxy-dispatcher.ts::configureProxyDispatcher`: - Reads HTTPS_PROXY / https_proxy / HTTP_PROXY / http_proxy. - If set, installs `undici.ProxyAgent` as the global fetch dispatcher via `setGlobalDispatcher`. From that point on every server-side `fetch()` routes through the proxy. - Idempotent — multiple endpoints can call it without re-installing. - No-op when no proxy env var is present (production / CI). - Dynamic `require('undici')` so a build target that strips undici doesn't crash at import time. Wired into `image-search.ts` at module top so the dispatcher is configured before the first request lands. Other endpoints making external fetches can opt in with the same single-line call. Verified standalone via Bun: with the helper in place, `fetch('https://api.openverse.org/v1/images/?q=salmon+sushi')` returns 240 results. The dev server itself needs a restart to pick up the server-side change (Vite server-code HMR doesn't re-evaluate Nitro modules). |
||
|---|---|---|
| .. | ||
| public | ||
| server | ||
| src | ||
| CLAUDE.md | ||
| components.json | ||
| dev.ts | ||
| package.json | ||
| tsconfig.json | ||
| vite.config.ts | ||