Skip to content
TypeScript
4.8 KB
Raw Blame
---
title: Apps
description: Prisma Compute apps as Stack resources — framework builds or Effect-native services, env wiring, custom domains, and a local dev command.
---

`Prisma.Compute` deploys an application onto Prisma's managed
runtime. One resource covers the whole path: optional build, artifact
upload, deployment, health check, and promotion — see
[Deployments](/prisma/compute/deployments) for the lifecycle.

## Framework apps

For frontend frameworks, prefer the [`Prisma.Website` family](/prisma/frontend/websites).
It provides framework-specific builds and native dev servers with the
same `rootDir`, `env`, `assets`, `dev`, and `domain` vocabulary as other
providers. Its output still runs on Bun in Compute, including static
sites. Use `Prisma.Compute` directly for custom builds, server apps,
and the Effect-native handlers below.

Point `path` at the app. With `build: "auto"`, alchemy detects the
framework, builds it, archives the output, and deploys the correct
server entrypoint:

```typescript
const app = yield* Prisma.Compute("api", {
  project,
  path: "./app",
  build: "auto",
  healthCheck: { path: "/api/health" },
  destroyOldDeployment: true,
});
```

The server must listen on `PORT` (injected at runtime). Auto-build
supports Bun, Next.js, Nuxt, Astro, TanStack Start, Vite, and NestJS. Generic
Vite projects are deployed as static SPAs. Use an
explicit build object when an app needs a custom command, output
directory, or entrypoint.

When `Prisma.Project` creates its default database, Prisma injects
system-managed `DATABASE_URL` and `DATABASE_URL_POOLED` values into
Compute deployments. Leave those keys out of `env`. For a standalone
`Prisma.Postgres` database, create a `Prisma.Connection` and pass its
outputs explicitly as shown in [Connections](/prisma/data/connections).

`app.url` is the deployed endpoint.

## Static sites

Generic Vite apps work with `build: "auto"`. To deploy a directory that already
contains static files, set `build.type` to `"static"` and point `outdir` at it.
Alchemy packages the files with the HTTP entrypoint Prisma Compute requires;
the application does not need its own server file or runtime dependency:

```typescript
const site = yield* Prisma.Compute("web", {
  project,
  path: "./site",
  build: {
    type: "static",
    outdir: ".",
  },
});
```

Add `command` when the output directory needs to be built first:

```typescript
const site = yield* Prisma.Compute("web", {
  project,
  path: "./app",
  build: {
    type: "static",
    command: "bun run build",
    outdir: "dist",
    spa: true,
  },
  dev: { command: "bun run dev", port: 5173 },
});
```

Set `spa: true` for client-side routers so unmatched paths serve
`index.html`. Leave it disabled for static sites that should return `404` for
missing files. Directory indexes redirect to a trailing-slash URL so relative
asset links resolve correctly.

For static builds, `archiveIgnore` patterns are relative to `outdir`. The
configured index page must remain in the archive; excluding it rejects the
deployment.

## Effect-native apps

Pass `main` and an Effect body instead of a build, and the app is
bundled from your Stack file — same shape as an Effect-native
Cloudflare Worker or Lambda:

```typescript
export default Prisma.Compute(
  "api",
  { project, main: import.meta.filename },
  Effect.gen(function* () {
    const db = yield* Prisma.Connect(connection);
    const sql = yield* SQL.Postgres({ url: db.databaseUrl });

    return {
      fetch: Effect.gen(function* () {
        const users = yield* sql`SELECT * FROM users`;
        return yield* HttpServerResponse.json(users);
      }),
    };
  }).pipe(Effect.provide(Prisma.ConnectBinding)),
);
```

## Custom domains

Creating the resource starts DNS and certificate
provisioning; use `domain.dnsRecords` to configure DNS and inspect
`domain.status` before directing production traffic:

```typescript
const domain = yield* Prisma.CustomDomain("api-domain", {
  app,
  hostname: "api.example.com",
});
```

Changing the hostname or app in place is intentionally rejected.
Create a second domain, verify DNS and TLS, cut traffic over, and then
remove the old resource.

## Local dev

Under `bun alchemy dev`, `dev.command` runs your app locally (e.g.
`vite dev`) with the same env the deployed app would see — including
connection bindings, which resolve to the local
[dev database](/prisma/data/postgres#local-dev):

```typescript
const app = yield* Prisma.Compute("web", {
  project,
  path: ".",
  dev: { command: "bun run dev" },
  env: { DATABASE_URL: connection.databaseUrl },
});
```

## Where next

- [Deployments](/prisma/compute/deployments) — health-checked
  promotion, rollback, and deployment reuse.
- [Connections](/prisma/data/connections) — the env and binding
  wiring in detail.

Reference:

- [Compute API reference](/providers/prisma/compute)
- [CustomDomain API reference](/providers/prisma/customdomain)