import { LOGO_96 } from './logo'; export const BADGE_ORIGIN = 'https://badge.midscenejs.com'; /** Public discovery endpoints; independent of badge result parameters. */ export function siteResponse(request: Request): Response | undefined { const path = new URL(request.url).pathname; if (path === '/favicon.ico') { return new Response(null, { status: 308, headers: { Location: '/favicon.svg', 'Cache-Control': 'public, max-age=86400', }, }); } let body: string; let contentType: string; if (path === '/favicon.svg') { body = ``; contentType = 'image/svg+xml'; } else if (path === '/robots.txt') { body = `User-agent: *\nAllow: /\nSitemap: ${BADGE_ORIGIN}/sitemap.xml\n`; contentType = 'text/plain; charset=utf-8'; } else if (path === '/sitemap.xml') { body = `${['en', 'zh'].map((lang) => `${BADGE_ORIGIN}/?lang=${lang}`).join('')}`; contentType = 'application/xml; charset=utf-8'; } else return undefined; return new Response(request.method === 'HEAD' ? null : body, { headers: { 'Content-Type': contentType, 'Cache-Control': path === '/favicon.svg' ? 'public, max-age=86400' : 'public, max-age=3600', 'X-Content-Type-Options': 'nosniff', }, }); }