3 min readv1.0.68
Edge Function: enrich-url
Deno Edge Function extracting OpenGraph metadata, YouTube oEmbed previews, and fallback thumbnails.
Function Overview#
The `enrich-url` Supabase Edge Function (supabase/functions/enrich-url/index.ts) runs on Deno at Cloudflare Edge locations globally.
When a URL is submitted, the function:
- Validates and sanitizes the target URL.
- Checks specialized scrapers (YouTube, GitHub, Spotify, Twitter/X).
- Fetches the page HTML and extracts OpenGraph (
og:title,og:image,og:description), Twitter Card tags, and standard meta tags. - Returns a clean JSON payload for instant client storage.
YouTube oEmbed & Fallback Thumbnail Resolver#
For YouTube links (including watch, shorts, embed, live, and youtu.be short URLs):
- Video ID Parser: Robust regex parser extracts the 11-character video ID.
- Unauthenticated oEmbed API: Queries
https://www.youtube.com/oembed?url=...&format=jsonto retrieve official video title, author, and high-res thumbnail. - Deterministic Fallback: If the video is restricted or oEmbed is blocked, deterministically resolves to Google CDN:
https://i.ytimg.com/vi/<id>/hqdefault.jpg.
CORS & Edge Caching#
- Fully configured with permissive CORS headers (
Access-Control-Allow-Origin: *) to support calls from mobile apps, desktop clients, and browser extensions. - Responses include
Cache-Control: public, max-age=86400to reduce redundant scraping on viral links.
Questions or suggestions for this documentation?