Premier League Predictor: Astro — Chapter 1, Exercise 3 ==================================================== TASK Set up the Astro project and the /api/health route yourself, confirm it responds with a real server request, then explain — in your own words — the real difference between a page that's server-rendered on every request under output: 'server' and one that opts back into static prerendering with export const prerender = true. SOLUTION Steps to complete this exercise: 1. Scaffold the project and add the Node adapter: npm create astro@latest -- pl-predictor-astro cd pl-predictor-astro npx astro add node npm install better-sqlite3 2. Set astro.config.mjs exactly as shown in the chapter: import { defineConfig } from 'astro/config'; import node from '@astrojs/node'; export default defineConfig({ output: 'server', adapter: node({ mode: 'standalone' }), }); 3. Create src/pages/api/health.ts exactly as shown in the chapter. 4. Start the dev server: npm run dev 5. Visit http://localhost:4321/api/health in a browser — it should return {"status":"ok"}. Written explanation: Under output: 'server', a page or API route with no prerender setting is built fresh on every single incoming request — the server runs the page's own code (or the endpoint's GET/POST function) each time a visitor loads it, which is exactly what's needed for something that genuinely changes request to request, like a league table that reflects whatever the database currently holds, or an API route that reads or writes real data. A page marked export const prerender = true instead gets built once, ahead of time, into a plain static HTML file during the build step — the same way every page works in Astro's own default static mode. Once built, that page is served as a fixed file with no server-side work happening on each visit at all, which is faster and cheaper to serve, but only correct for content that doesn't need to reflect anything that changes between requests. In short: output: 'server' switches the whole project's default from "build once" to "run every time," and prerender = true is the escape hatch that lets one specific page opt back into the faster "build once" behavior when it doesn't actually need to be dynamic. WHY THIS WORKS AS AN ANSWER ---------------------------- It walks through every real setup step in order, confirms the health check works, and then gives a written explanation that correctly identifies the real mechanism on both sides — request-time execution vs. build-time generation — rather than just restating which setting is "faster," which is the actual point Chapter 10 later builds on.