项目文件夹

文件
wehub-resource-sync c48612c494
CI / E2E Tests (push) Has been cancelled
CI / Lint, Typecheck & Unit Tests (push) Has been cancelled
Docs Build / Build docs site (push) Has been cancelled
Publish @openmaic packages / Build, validate & publish (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:03:23 +08:00

18 行
739 B
TypeScript

/**
* A fetch implementation that routes asset requests through the same-origin
* /api/proxy-media endpoint, bypassing cross-origin CORS restrictions that block
* direct browser fetches to CDNs like cdn.tailwindcss.com or CORS-locked image hosts.
* The proxy validates the URL server-side (SSRF guard) and returns the bytes.
*/
export function createProxiedFetch(): typeof fetch {
return (async (input: RequestInfo | URL) => {
const url =
typeof input === 'string' ? input : input instanceof URL ? input.href : String(input);
return fetch('/api/proxy-media', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url }),
});
}) as unknown as typeof fetch;
}