Docs/Backend/Edge Function: enrich-url
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:

  1. Validates and sanitizes the target URL.
  2. Checks specialized scrapers (YouTube, GitHub, Spotify, Twitter/X).
  3. Fetches the page HTML and extracts OpenGraph (og:title, og:image, og:description), Twitter Card tags, and standard meta tags.
  4. 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):

  1. Video ID Parser: Robust regex parser extracts the 11-character video ID.
  2. Unauthenticated oEmbed API: Queries https://www.youtube.com/oembed?url=...&format=json to retrieve official video title, author, and high-res thumbnail.
  3. 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=86400 to reduce redundant scraping on viral links.
Questions or suggestions for this documentation?