Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created March 9, 2022 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save velotiotech/6657a8ce10ad7bea0f597f933d62c941 to your computer and use it in GitHub Desktop.
Save velotiotech/6657a8ce10ad7bea0f597f933d62c941 to your computer and use it in GitHub Desktop.
import type { NextFetchEvent } from 'next/server';
import { NextResponse } from 'next/server';
export function middleware(event: NextFetchEvent) {
// gram the user's location or use India for default
const country = event.request.geo.country.toLowerCase() || 'IND';
//rewrite to static, cached page for each local
return event.respondWith(NextResponse.rewrite(`/routeName/${country}`));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment