IP Blocking with Upstash is a Next.js boilerplate from Vercel's examples repository that demonstrates how to block IP addresses at the edge using Upstash Redis. It runs on Vercel's Edge Middleware, so IP checks happen before requests reach your origin server. The template is part of Vercel's edge middleware collection, alongside related examples like Bot Protection with Botd and IP Blocking with DataDome.
What is IP Blocking with Upstash?
IP Blocking with Upstash is an open-source example that shows how to enforce an IP blocklist in Redis at the edge. Built on Next.js, it uses Upstash's REST API to store and query blocked IPs, and it ships with a one-click Vercel deployment link that pre-configures the required environment variables. The template is maintained as part of the Vercel examples repository and includes a live demo at edge-functions-ip-blocking.vercel.app.
Key Features
- Edge middleware — The IP blocking logic runs in Next.js middleware at the edge, so requests are evaluated on Vercel's edge network before they hit your application.
- Upstash Redis integration — The template reads and writes to Upstash via its REST API, using two environment variables:
UPSTASH_REST_API_DOMAINandUPSTASH_REST_API_TOKEN. - One-click deploy — A deploy button and pre-built clone URL let you deploy to Vercel without manual setup; the URL automatically fills in the Upstash environment variables.
- Local development — Bootstrap the project with
pnpm create next-app --exampleand runpnpm devfor a local development server. - Tailwind CSS — Styling is handled with Tailwind, keeping the demo UI minimal and customizable.
- Related examples — The repository includes sibling templates for bot protection (Botd, DataDome) and IP blocking with DataDome, so you can compare approaches.
Who is it for?
- Next.js developers who want a reference implementation for edge middleware, especially around access control and security.
- Teams using Upstash as their Redis provider and needing IP-based request filtering.
- Vercel users who want a quick starting point for edge functions that can be extended to rate limiting, allowlists, or bot detection.
What can you do with it?
- Block specific IPs — Add an IP address to Upstash Redis, and the middleware will deny requests from that IP at the edge.
- Protect an API or admin area — Use the blocklist to restrict access to sensitive routes without loading a full backend.
- Learn edge middleware patterns — Study how to integrate external REST APIs inside Next.js middleware and deploy to Vercel.
How does it work?
First, create an Upstash account and a Redis database. Then copy the .env.example file to .env.local, fill in UPSTASH_REST_API_DOMAIN and UPSTASH_REST_API_TOKEN with your database credentials, and run pnpm dev. The middleware will query Upstash for each incoming request's IP and block matches.
FAQ
Do I need an Upstash account?
Yes, the template requires Upstash because it stores the IP blocklist in Upstash Redis and communicates via the Upstash REST API.
How do I deploy this to Vercel?
You can use the one-click deploy link in the repository to clone and deploy immediately. The link sets the environment variables and project names for you, or you can clone the repo and deploy manually from your Vercel dashboard.
Can I use a different Redis provider?
The code is written specifically against Upstash's REST API, so switching providers would require modifying the middleware to use another client or HTTP interface.
Is the demo still live?
The demo URL is https://edge-functions-ip-blocking.vercel.app; availability depends on Vercel hosting and may change, but it is the official demo referenced in the repository.
What other templates are similar?
The repository lists related edge middleware examples: Bot Protection with Botd, Bot Protection with DataDome, and IP Blocking with DataDome. These cover different services and use cases.








