Edge Utils
LiveLibrary
Production-ready toolkit for Contentstack Launch Edge Functions.
What is it
Edge Utils is a lightweight toolkit for Contentstack Launch Edge Functions. (Contentstack Launch is Contentstack's high-performance frontend hosting platform; Edge Functions are small bits of code that run on its CDN edge — close to the user — before a request reaches your origin.) It bundles the helpers you reach for again and again at the edge — security, auth, geo, routing, and Next.js compatibility — so you're not rewriting the same boilerplate in every handler.
With it you can block AI crawlers, add Basic Auth scoped to specific hostnames, read geo data straight from request headers, fix RSC header issues behind the Launch proxy, and declare path-and-method-based redirects. The utilities you import carry no runtime dependencies, and the package bundles Wrangler so local testing works without a separate install. Three CLIs ship alongside: create-launch-edge scaffolds your edge function and wrangler.toml; launch-edge-test-local starts a local Wrangler dev server against your running app; and launch-config interactively builds a launch.json for config-driven redirects, rewrites, and cache priming with bulk CSV/JSON import support.
Why you need it
- Edge handlers are fiddly to write from scratch — these are production-ready, drop-in utilities you compose into a handler.
- Security first: block AI crawlers and manage IP access with a single call.
- Lean edge code: nothing you import pulls in runtime deps, so your edge bundle stays small and fast.
- Batteries included: Wrangler ships with the package, so npx and local testing just work without a separate install.
User guide — quickstart
- 1
Install the package
Add Edge Utils to the project you deploy to Contentstack Launch.
npm install @aryanbansal-launch/edge-utils - 2
Scaffold the edge function
Run this from your project root (where package.json lives). It creates a functions/ directory, a starter functions/[proxy].edge.js with production-ready boilerplate, and a wrangler.toml for local testing.
npx create-launch-edge - 3
Import only what you need
Open functions/[proxy].edge.js and pull in the specific helpers your handler uses.
import { blockAICrawlers, redirectIfMatch, passThrough } from "@aryanbansal-launch/edge-utils"; - 4
Wire your handler in order
Call each utility in sequence. When a function returns a Response, return it immediately; otherwise keep going until passThrough(request) sends traffic on to the origin.
- 5
Test locally before deploying
Run the interactive wizard to pick a preset (redirect, JSON route, basic auth, bot block, Next.js RSC), then start your app in another terminal, then start the local Wrangler dev server. Traffic flows: browser → local Worker → your handler → your running app. Open the URL Wrangler prints (typically http://localhost:8787) to test. You can also pass --port or --var BACKEND_URL to override defaults.
# Step 1: pick a preset and scaffold local files npx launch-edge-local # Step 2: start your app (in another terminal) npm run dev # Step 3: start the local edge worker npx launch-edge-test-local # or with overrides: npx launch-edge-test-local --var BACKEND_URL=http://127.0.0.1:5173 - 6
Manage config-driven redirects with launch-config
For static redirects, rewrites, and cache priming URLs that don't need dynamic logic, use the interactive CLI to build a launch.json at your project root. Supports one-by-one entry or bulk import from a CSV or JSON file. You can use both launch.json and an edge function on the same project — bulk static rules in launch.json, dynamic logic (geo, cookies, A/B tests) in the edge function.
npx launch-config # Example CSV format for bulk import (redirects.csv): # source,destination,statusCode # /old-blog/:slug,/blog/:slug,301 # /products/old-sku,/products/new-sku,308 - 7
Deploy — and get help if stuck
Deploy the function to Contentstack Launch as usual. If you need a reminder of all available utilities and commands, run the help command.
npx launch-help
Under the hood
Works with: Contentstack Launch Edge Functions
Published on npm
Ready to try Edge Utils?