The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | --- |
| 2 | title: Next.js |
| 3 | description: Deploy Next.js to Prisma Compute with Prisma.Website.Nextjs — a normal Next server on Bun, not OpenNext, and next dev locally. |
| 4 | sidebar: |
| 5 | order: 9 |
| 6 | --- |
| 7 | |
| 8 | import PackageManagers from "../../../../components/PackageManagers.astro"; |
| 9 | |
| 10 | export const devDeps = "@alchemy.run/frontend-frameworks @vercel/nft"; |
| 11 | |
| 12 | `Prisma.Website.Nextjs` runs a real [Next.js](https://nextjs.org) |
| 13 | `next build`, then hosts a normal Next server on **Bun in Prisma Compute**. |
| 14 | The shared Node target uses `next({ dev: false })`, `prepare()`, and |
| 15 | `getRequestHandler()`. The build output, public assets, and runtime |
| 16 | dependencies are packaged for a `tar.gz` upload; there is no Docker |
| 17 | image or registry. |
| 18 | |
| 19 | This is **not OpenNext**. App Router and Pages Router use Next's own |
| 20 | server, including server components, API routes, server actions, and |
| 21 | SSR. ISR and image optimization follow the normal Next server path, |
| 22 | not an external cache or image service provisioned by Alchemy. |
| 23 | |
| 24 | ## Install |
| 25 | |
| 26 | Install the build-time integration; the resource loads `/nextjs/node` |
| 27 | from your project. Keep `next`, `react`, and `react-dom` as app dependencies. |
| 28 | |
| 29 | <PackageManagers dev={devDeps} /> |
| 30 | |
| 31 | ## Configure Next.js |
| 32 | |
| 33 | `next.config.*` loads natively. There is no adapter to install and no |
| 34 | `open-next.config.ts`. Pass `rootDir` if your Next app is not at the |
| 35 | Stack root. |
| 36 | |
| 37 | ## Declare the Website |
| 38 | |
| 39 | ```typescript |
| 40 | // alchemy.run.ts |
| 41 | import * as Prisma from "@alchemy.run/prisma"; |
| 42 | |
| 43 | export const Website = Prisma.Website.Nextjs("Website"); |
| 44 | ``` |
| 45 | |
| 46 | A live deployment creates a database-less Prisma project if you omit |
| 47 | `project`. Pass an existing project to share it with other apps. |
| 48 | |
| 49 | ## Add it to the Stack |
| 50 | |
| 51 | ```typescript |
| 52 | // alchemy.run.ts |
| 53 | import * as Alchemy from "alchemy"; |
| 54 | import * as Effect from "effect/Effect"; |
| 55 | |
| 56 | export default Alchemy.Stack( |
| 57 | "MyNextjsSite", |
| 58 | { providers: Prisma.providers(), state: Alchemy.localState() }, |
| 59 | Effect.gen(function* () { |
| 60 | const site = yield* Website; |
| 61 | return { url: site.url }; |
| 62 | }), |
| 63 | ); |
| 64 | ``` |
| 65 | |
| 66 | `site.url` is the Compute endpoint on deploy and Next's local URL in dev. |
| 67 | |
| 68 | ## Add environment variables |
| 69 | |
| 70 | ```diff lang="typescript" |
| 71 | export const Website = Prisma.Website.Nextjs("Website", { |
| 72 | + env: { |
| 73 | + GREETING: "Hello from Alchemy!", |
| 74 | + API_BASE: "https://api.example.com", |
| 75 | + }, |
| 76 | }); |
| 77 | ``` |
| 78 | |
| 79 | Values are applied before `next build` and `next dev`, and passed to |
| 80 | Compute. `NEXT_PUBLIC_*` values are inlined into the browser bundle; |
| 81 | other keys remain server-side. `env` accepts strings or `Redacted` secrets. |
| 82 | |
| 83 | ## Read the environment in server code |
| 84 | |
| 85 | ```typescript |
| 86 | // app/api/hello/route.ts |
| 87 | export function GET() { |
| 88 | return Response.json({ greeting: process.env.GREETING ?? "hello" }); |
| 89 | } |
| 90 | ``` |
| 91 | |
| 92 | Route handlers, server components, and server actions read the Bun |
| 93 | process environment with `process.env`. |
| 94 | |
| 95 | ## Local dev |
| 96 | |
| 97 | ```sh |
| 98 | bun alchemy dev |
| 99 | ``` |
| 100 | |
| 101 | Alchemy runs `next dev` with native HMR rather than deploying. The |
| 102 | Website creates no Prisma resources. Use `.pipe(Alchemy.remote())` |
| 103 | to deploy live during dev instead. |
| 104 | |
| 105 | ## Custom domain |
| 106 | |
| 107 | ```typescript |
| 108 | const site = yield* Prisma.Website.Nextjs("Web", { |
| 109 | domain: "app.example.com", |
| 110 | }); |
| 111 | ``` |
| 112 | |
| 113 | This creates `Prisma.CustomDomain` and changes `site.url` to the HTTPS |
| 114 | hostname. |
| 115 | Configure returned DNS records yourself and verify domain status before |
| 116 | cutover; see [Custom domains](/prisma/frontend/websites#custom-domains). |
| 117 | |
| 118 | ## Where next |
| 119 | |
| 120 | - [Next.js API](/providers/prisma/website/nextjs). |
| 121 | - [Next.js example](https://github.com/alchemy-run/alchemy/tree/main/examples/prisma-website-nextjs). |
| 122 | - [Websites](/prisma/frontend/websites) and [Compute apps](/prisma/compute/apps). |
| 123 | - [Connections](/prisma/data/connections) — database environment wiring. |