Created
April 10, 2023 09:07
-
-
Save Accudio/0bfa30d21acdd4a21bfcc57b53db5373 to your computer and use it in GitHub Desktop.
Multiple currencies within cookies using Vercel Middleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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