2.0 alpha
These docs describe 2.0. Install it with @once-ui-system/core@alpha.
On 1.8.x? Read the 1.x docs
TrademarkTrademarkDocs
Ctrl k
Search docs...
Utils

handleOGProxy

Updated: July 24, 2026
View on GitHub
The handleOGProxy function is a server-side utility that proxies external images through your server. This is essential for displaying Open Graph images from external sources without CORS restrictions.
  • Proxies images from external URLs
  • Preserves original content type
  • Configurable cache control headers
  • Custom user agent support
  • Validates URLs to block SSRF (private IPs, localhost, non-HTTPS)
  • Optional domain allowlist via allowedDomains
  • Requires Node.js runtime (uses DNS resolution for hostname validation)
  • Handles errors gracefully
Create an API route that uses the utility: Then use the proxy in your client: Customize cache duration and user agent: External images often have CORS restrictions that prevent direct usage in web applications. By proxying images through your server:
  • Bypass CORS: Your server fetches the image and serves it from your domain
  • Caching: Reduce external requests with configurable cache headers
  • Privacy: Hide the original image URL from client-side code
  • Reliability: Handle external failures gracefully
Prop
Type
Default
request
Request
options
OGProxyOptions
options.userAgent
User agent string for the fetch request.
string'Mozilla/5.0 (compatible; OG-Proxy/1.0)'
options.cacheMaxAge
Cache duration in seconds (1 hour).
number3600
options.allowedDomains
When set, only these domains (and their subdomains) are permitted.
string[]
The function returns the image binary data with appropriate headers: The function returns appropriate error responses:
  • 400: Missing URL parameter or URL failed validation (blocked domain, private IP, etc.)
  • 500: Failed to fetch the image
  • Original status: If the external server returns an error, that status is forwarded
The useOgData hook automatically uses the proxy for external images: Both handleOGFetch and handleOGProxy validate URLs server-side before fetching:
  • Only HTTPS URLs are allowed
  • Private IPs, localhost, and link-local addresses are blocked
  • Embedded credentials in URLs are rejected
  • Redirect chains are followed and re-validated (up to 3 redirects)
Use allowedDomains to restrict fetching to trusted hosts in production: Consider also adding rate limiting at the route level to prevent abuse.
Edit this page on GitHub
TrademarkTrademark
Built with curiosity by Lorant One and the Design Engineers Club