import handler from './.open-next/worker.js'; import config from './next.config.js'; const rules = await config.headers(); const siteRule = rules.find(rule => rule.source === '/(.*)'); // One home: the old AI Resource Pro addresses and www all move to becomeapro.ai, keeping the path and query. const CANONICAL = 'becomeapro.ai'; const OLD_HOSTS = new Set(['www.becomeapro.ai', 'airesourcepro.com', 'www.airesourcepro.com', 'airesource.pro', 'www.airesource.pro']); export default { async fetch(request, env, ctx) { const url = new URL(request.url); if (OLD_HOSTS.has(url.hostname)) { return Response.redirect(`https://${CANONICAL}${url.pathname}${url.search}`, 301); } const response = await handler.fetch(request, env, ctx); const headers = new Headers(response.headers); const routeRule = rules.find(rule => rule.source === url.pathname && !rule.has); for (const rule of [siteRule, routeRule]) { for (const { key, value } of rule?.headers ?? []) headers.set(key, value); } return new Response(response.body, { status: response.status, statusText: response.statusText, headers }); }, };