Functions
Server-side functions and page exports.
getServerSideProps(ctx)
Async data loader, run per request. The context carries the full request: method, path, params, query, lowercased headers, parsed cookies, and locale. Return props, a redirect, or props plus response headers:
export async function getServerSideProps(ctx) {
const user = await auth(ctx.cookies['session']);
if (!user) {
return { redirect: { destination: '/login', permanent: false } };
}
return {
props: { name: user.name },
headers: { 'set-cookie': 'seen=1; Path=/; HttpOnly' }, // optional
};
}A page that returns response headers is automatically made uncacheable - caching a per-request set-cookie would replay one visitor's cookie to everyone.
export const revalidate
A number (seconds), or false to cache indefinitely. Controls the ISR cache TTL for the page. Pages without it render on every request.
getStaticPaths()
On static export, tells gio export which concrete paths to pre-render for a dynamic route: return { paths: [{ params: { id: "1" } }] }.
Route handler exports
route.ts files export GET / POST / PUT / PATCH / DELETE (API endpoints, SSE) and wsHandler (WebSockets) - see Route Handlers.