Deploy your Astro Site to Prisma Compute
Questi contenuti non sono ancora disponibili nella tua lingua.
Prisma Compute is a hosting platform for TypeScript applications that runs your Astro site as a server, using the Node.js adapter to serve prerendered pages and on-demand rendered routes.
This guide includes instructions for deploying to Prisma Compute from your terminal using the Prisma CLI.
Prerequisites
Section titled “Prerequisites”To deploy your Astro site to Prisma Compute, you will need:
- An Astro project
- A Prisma Data Platform account
- npm or pnpm as your package manager
Project configuration
Section titled “Project configuration”Adapter
Section titled “Adapter”Prisma Compute runs a server process instead of hosting a folder of files. Add the Node.js adapter with the following astro add command, even if all of your pages are prerendered. This will install the adapter and configure it in standalone mode in your astro.config.mjs file in one step.
npx astro add nodepnpm astro add nodeYour pages are still prerendered by default, and the server created by the adapter serves them as static files. To render a page or endpoint on demand, opt it out of prerendering.
Prisma Composer
Section titled “Prisma Composer”A deployment to Prisma Compute is described in TypeScript files that are read by Prisma Composer.
-
Install the Prisma Composer packages and the Prisma CLI:
Terminal window npm install @prisma/composer @prisma/composer-prisma-cloudnpm install -D prismaTerminal window pnpm add @prisma/composer @prisma/composer-prisma-cloudpnpm add -D prisma -
Create a
service.tsfile in the root of your project that points to the server entry file built by Astro. Setdependencies: 'external'so that the deployment includes the packages this file imports:service.ts import node from '@prisma/composer/node';import { compute } from '@prisma/composer-prisma-cloud';export default compute({name: 'web',deps: {},build: node({module: import.meta.url,dir: './dist',entry: 'server/entry.mjs',dependencies: 'external',}),}); -
Create a
module.tsfile in the root of your project to add your service to a Prisma Compute project. Pass the name of your project (e.g.my-astro-site) as the first argument ofmodule():module.ts import { module } from '@prisma/composer';import web from './service.ts';export default module('my-astro-site', ({ provision }) => {provision(web);}); -
Create a
prisma.config.tsfile in the root of your project. Theregionoption sets where the project is created on the first deployment. See the regions supported by Prisma Compute for the available values.prisma.config.ts import { defineConfig as composer } from '@prisma/composer/config';import { nodeBuild } from '@prisma/composer/node/control';import { prismaCloud, prismaState } from '@prisma/composer-prisma-cloud/control';import { definePrismaConfig } from 'prisma/config';export default definePrismaConfig({composer: composer({entry: './module.ts',extensions: [prismaCloud({ region: 'us-east-1' }), nodeBuild()],state: prismaState(),}),}); -
Add the local state folders created by Prisma Composer to your
.gitignorefile:.gitignore /.alchemy/.prisma-composer
How to deploy
Section titled “How to deploy”-
Sign in to your Prisma Data Platform account. This command opens your browser.
Terminal window npx prisma auth loginTerminal window pnpm prisma auth login -
Build your site:
Terminal window npm run buildTerminal window pnpm run build -
Deploy your site:
Terminal window npx prisma deployTerminal window pnpm prisma deployThe first deployment creates the project. When the command finishes, it prints the URL of your site:
my-astro-site└─ web compute-service cps_abc123https://abc123.ewr.prisma.build -
To publish changes, build your site and run the
deploycommand again.