Skip to content

Instantly share code, notes, and snippets.

@Accudio
Created April 10, 2023 09:07
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 Accudio/0bfa30d21acdd4a21bfcc57b53db5373 to your computer and use it in GitHub Desktop.
Save Accudio/0bfa30d21acdd4a21bfcc57b53db5373 to your computer and use it in GitHub Desktop.
Multiple currencies within cookies using Vercel Middleware
import { rewrite } from '@vercel/edge';
import { RequestCookies } from '@edge-runtime/cookies'
// only run middleware on home page
export const config = {
matcher: '/',
}
export default function middleware(req) {
const cookies = new RequestCookies(req.headers)
const currency = cookies?.get('currency')?.value || 'eur'
return rewrite(new URL(`/${currency}`, req.url));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment