skies.dev

Help Stop the Russia-Ukraine War with Vercel Edge Functions

1 min read

If you're deploying to Vercel, you can use Edge Functions and Next.js Middleware to help stop the Russian invasion of Ukraine.

The idea is simple. Check if the request is from Russia. If it is, redirect to Arnold Schwarzenegger's anti-war appeal to the Russian people.

pages/middleware.ts
import type {NextRequest} from 'next/server';
import {NextResponse} from 'next/server';

export function middleware(req: NextRequest) {
  if (req.geo?.country === 'RU') {
    return NextResponse.redirect('https://www.youtube.com/watch?v=4e1BndTE6Lg');
  }

  return NextResponse.next();
}

Or if you prefer JavaScript:

pages/_middleware.js
import {NextResponse} from 'next/server';

export function middleware(req) {
  if (req.geo?.country === 'RU') {
    return NextResponse.redirect('https://www.youtube.com/watch?v=4e1BndTE6Lg');
  }

  return NextResponse.next();
}

In just a few lines of code, you can help stop the war. πŸ‡ΊπŸ‡¦

Hey, you! 🫡

Did you know I created a YouTube channel? I'll be putting out a lot of new content on web development and software engineering so make sure to subscribe.

(clap if you liked the article)