#Using server components to generate tokens
1 messages · Page 1 of 1 (latest)
Yes, you can write server-side code inside Server Components. When you run next build, Server Components consumed inside the app directory will run during the build, similar to traditional static-site generation. The resulting component will be rendered into static HTML for the initial page load and a static payload for client navigation between routes source (https://nextjs.org/docs/app/building-your-application/deploying/static-exports#server-components).
For example, you can fetch data from an API and use it in your Server Component:
export default async function Page() {
// This fetch will run on the server during `next build`
const res = await fetch('https://api.example.com/...');
const data = await res.json();
return <main>...</main>;
}