Skip to content

Next.js

DigitalOcean.Website.Nextjs deploys a Next.js project to App Platform. Deploy builds it on your machine, puts the output in one image, and the App runs Next.js’s own server, with its standalone output and the packages it needs installed into the image.

The build integration ships separately. It runs only at build time, so a dev dependency is enough:

Terminal window
pnpm add -D https://pkg.alchemy.run/@alchemy.run/frontend-frameworks/pr:3743:41147c9
alchemy.run.ts
import * as DigitalOcean from "@alchemy.run/digitalocean";
import * as Alchemy from "alchemy";
import * as Effect from "effect/Effect";
export const Website = DigitalOcean.Website.Nextjs("Website", { rootDir: "./web" });
export default Alchemy.Stack(
"MySite",
{ providers: DigitalOcean.providers(), state: Alchemy.localState() },
Effect.gen(function* () {
const site = yield* Website;
return { url: site.url };
}),
);

rootDir is the directory with the project’s package.json. site.url is the App’s HTTPS address. Deploy needs Docker and the team’s Container Registry, or a registry you declare.

alchemy.run.ts
export const Website = DigitalOcean.Website.Nextjs("Website", {
rootDir: "./web",
env: { GREETING: "Hello from DigitalOcean" },
});

env is set before the build and on the App, so build-time and run-time code see the same values:

app/page.tsx
export default function Page() {
return <h1>{process.env.GREETING ?? "hello"}</h1>;
}

region, instanceSizeSlug and instanceCount are passed to the App. See Websites.

alchemy dev runs Next.js’s own dev server with the same env instead of deploying, and site.url is its local address.