Skip to content

Instantly share code, notes, and snippets.

@sbennettmarqeta
Created September 12, 2022 21:24
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 sbennettmarqeta/d3c7e9fe66bedc6d83c4b08fb42169c1 to your computer and use it in GitHub Desktop.
Save sbennettmarqeta/d3c7e9fe66bedc6d83c4b08fb42169c1 to your computer and use it in GitHub Desktop.
export default async (request, context) => {
const url = request?.url;
if (/\/(static|_next|fonts)/gi.test(url)) {
return;
}
const forwardedFor = request.headers.get('X-Forwarded-For');
context.log(`Country toggle function invoked ${context.geo.country.code} // ${context.geo.city} // ${forwardedFor}`);
const countryCode = context?.geo?.country?.code;
context.cookies.set({ name: 'mqCountryToggle', value: countryCode ? countryCode : 'US' });
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment