Week 06 / Routes · server and client code · TypeScript · API routes
Give it a home with Next.js.
The idea
A route maps a URL to a page. Server code can keep private credentials away from a visitor’s browser; client code handles interactions in the browser. Environment variables hold configuration outside the source code.
Keep secrets on the server
// Server route: secret stays on the server
export async function GET() {
const response = await fetch(privateApiUrl, {
headers: { Authorization: process.env.API_KEY! },
});
return Response.json(await response.json());
}Build it
Work through these steps in your own project. Check them off as you go; your checklist stays in this browser.
Which parts must run on the server, and what information is safe to send to the browser?
Notes save in this browser.