// src/pages/api/contact.ts — requires output: 'server' (or prerender = false) export async function POST({ request }) { const body = await request.json(); // in a real app this would validate and store body.message somewhere console.log('Received message:', body.message); return new Response( JSON.stringify({ status: 'received' }), { headers: { 'Content-Type': 'application/json' } } ); } WHY A PURELY STATIC BUILD COULDN'T SUPPORT THIS: - A POST endpoint exists specifically to handle data submitted by a real visitor, at the moment they submit it - there is no way to know what that data will be ahead of time, at build time, the way getStaticPaths() needs to know every dynamic route's own value in advance. - Astro's static output mode produces a fixed set of files once, during the build. A file has no way to "run" server-side logic in response to an incoming POST request afterward - there's no server process listening for it at all once the static files are deployed. - output: 'server' (or a per-endpoint prerender = false in a mixed project) is what actually keeps a real server process running, capable of executing this POST function fresh for every incoming request, with access to that specific request's own real body data. Notes: - This is the same underlying reason the future Website Rebuild with Astro course's own admin interface would need server output: any endpoint that has to react to data it couldn't have known about at build time needs a real server behind it, not a static file.