1
ewpratten.com/static/functions/_middleware.js

20 lines
732 B
JavaScript

async function redirect_secondary_domains(context) {
// Parse the request URL
let url = new URL(context.request.url);
// If the request is for any of the secondary domains, redirect to the primary domain
var secondary_domains = ['test.ewp.fyi', 'va3zza.com', 'evan.pratten.ca', 'evan.warren.pratten.ca'];
if (secondary_domains.includes(url.hostname)) {
url.searchParams.set("utm_source", url.hostname);
url.searchParams.set("utm_campaign", "secondary_domains");
url.hostname = 'ewpratten.com';
return Response.redirect(url, 302);
}
// Otherwise, continue the request chain
return context.next();
}
// Chaining
export const onRequest = [redirect_secondary_domains];