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

handleOGFetch

Updated: July 24, 2026
View on GitHub
The handleOGFetch function is a server-side utility that fetches and parses Open Graph metadata from any URL. It's designed to be used in Next.js API routes to extract title, description, image, and favicon information from web pages.
  • Fetches HTML content from URLs with configurable timeout
  • Extracts Open Graph metadata (title, description, image)
  • Falls back to standard HTML meta tags if OG tags aren't available
  • Decodes HTML entities in text content
  • Supports custom user agents
  • 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)
Create an API route that uses the utility: Then fetch metadata from your client: Customize timeout, user agent, and entity decoding: The function returns a JSON response with the following structure:
Prop
Type
Default
request
Request
options
OGFetchOptions
options.timeout
number5000
options.userAgent
string'Mozilla/5.0 (compatible; OG-Fetcher/1.0)'
options.decodeEntities
booleantrue
options.allowedDomains
When set, only these domains (and their subdomains) are permitted.
string[]
The function returns appropriate error responses:
  • 400: Missing URL parameter or URL failed validation (blocked domain, private IP, etc.)
  • 500: Failed to fetch or parse the URL
Combine with the useOgData hook for seamless client-side integration:
Edit this page on GitHub
TrademarkTrademark
Built with curiosity by Lorant One and the Design Engineers Club