---
url: /saas-starter/v0.10.0/guide/deployment.md
---
# Deployment

::: tip What this page covers
Every choice of `--Persistence`, `--Auth`, `--IncludeTests` and `--Aspire`: a label says
which options a part is for. The copy in your app's `docs/` folder has only the parts for yours.
`ApiHost` stands for your app's name.
:::

`deploy/` has everything to run the app on a small server: a production `docker-compose.yml`
(PostgreSQL, the app's container, and Caddy for automatic HTTPS) and a step-by-step guide in
[deploy/README.md](./deploy-to-a-server.md). The container image is built with
`dotnet publish src/ApiHost -c Release /t:PublishContainer`.

The rest of this page applies wherever you run it.

## Publishing

`dotnet publish` builds the React app into `wwwroot` and pre-generates Wolverine's handler code,
so production starts quickly and compiles nothing at runtime.

```bash
dotnet publish src/ApiHost -c Release -o publish
cd publish                                         # run from here, so it finds wwwroot
ASPNETCORE_ENVIRONMENT=Production dotnet ApiHost.dll
```

::: info Marten
Marten creates and updates its tables when the app starts.
:::

::: info EF Core
EF Core migrations are applied when the app starts.
:::

For health checks, see [Observability](./observability.md).

## What the published app serves

* The pages in `src/Client/src/pages.ts`: the public ones (`index: true`, such as `/`) as HTML
  the build pre-rendered, and the others as a page that starts the app. Any other path gets that
  page with status 404 (the app shows its not-found page), so search engines don't index made-up
  URLs. The HTML is sent with `Cache-Control: no-cache`, so browsers and CDNs pick up a new
  deployment at once.
* Built files under `/assets/`, with content hashes in their names, cached for a year.
* `/robots.txt` (everything may be crawled except `/api/`) and `/sitemap.xml` (the pages marked
  `index` in `pages.ts`), using the address the visitor used.
* Unknown `/api/` paths answer 404 as `ProblemDetails`; errors are `ProblemDetails` with a trace ID
  that matches the logs.

## Configuration

Set these with environment variables (or any ASP.NET Core configuration source):

| Setting | Example |
|---|---|
|  `ConnectionStrings__Marten` | `Host=db;Database=apihost;Username=app;Password=…` |
|  `ConnectionStrings__Postgres` | `Host=db;Database=apihost;Username=app;Password=…` |
| `ASPNETCORE_URLS` | `http://+:8080` |
| `ASPNETCORE_FORWARDEDHEADERS_ENABLED` | `true` behind a reverse proxy, so the app sees clients' real addresses and HTTPS |
| `OTEL_EXPORTER_OTLP_ENDPOINT` | Optional: where to send traces, metrics and logs |
| `Storage__Provider` | Where uploaded files go: `Local` (default), `S3` or `AzureBlob`, with that provider's settings ([file storage](./file-storage.md)) |
| `Storage__Local__RootPath` | Local disk: the folder for files; put it on a volume in a container |
| `Analytics__GoogleTagManagerId` | Optional: a Google Tag Manager container, loaded once visitors accept cookies; also `Analytics__ConnectOrigins__0`, `Analytics__ScriptOrigins__0` for its tags ([analytics](./analytics.md)) |
| `Legal__TermsUrl`, `Legal__PrivacyUrl` | Optional: your terms of service and privacy policy (a path such as `/terms` or a full address), linked in the footer |
|  `Legal__Version` | The version of those documents (default `1`): people accept it at sign-up, and are asked again when it goes up ([accounts](./accounts.md#terms-and-privacy-policy)) |
| `Attachments__MaxBytes`, `Attachments__MaxPerTodo` | The largest file that can be attached to a Todo (default 25 MB; with local disk, raise `Storage__Local__MaxUploadBytes` too) and how many one Todo can have (default 10) |

::: info With accounts
| `Jwt__SigningKey` | A random secret of at least 32 bytes ([how to change it](./how-to/rotate-the-signing-key.md)) |
| `Jwt__SessionLifetimeDays` | How long a session lasts at most before the user signs in again (default 30; 0 for no limit). Sessions also end after `Jwt__RefreshTokenLifetimeDays` (14) unused |
| `App__ClientUrl` | The app's public address, such as `https://app.example.com`: links in emails use it |
| `Email__Smtp__Host`, `Email__Smtp__Port`, `Email__Smtp__Security`, `Email__Smtp__UserName`, `Email__Smtp__Password`, `Email__Smtp__From` | Your email provider's SMTP settings ([how-to](./how-to/configure-email.md)) |
| `Accounts__AdminEmails__0` | Your email: that account becomes an admin once its email is confirmed (more: `__1`, `__2`, ...) |
| `Accounts__AllowRegistration` | `false` to allow only invited people to create accounts (default `true`) |
| `Accounts__AuthAttemptsPerMinute` | Sign-in and account attempts allowed per client address per minute |
| `Accounts__RequireTwoFactorForAdmins` | `true` to let admins use the back office only with two-factor authentication (or passkeys only) on their account (default `false`, [more](./accounts.md#two-factor-authentication)) |
| `Accounts__TwoFactorIssuer` | The name authenticator apps show next to the account (default: the app's name) |
| `Accounts__PasswordBlockedWords__0` | Words new passwords mustn't be built from, besides the email and the app's name: your product and company names ([more](./accounts.md#passwords)) |
| `Accounts__RejectBreachedPasswords` | `true` to refuse new passwords known from data breaches, checked with Have I Been Pwned without sending the password (default `false`, [more](./accounts.md#breached-passwords)). The server must be able to reach `api.pwnedpasswords.com` |
| `Accounts__AskForProductNews` | `false` if the app doesn't send product news: hides the "Send me product news" box at sign-up and in Settings (default `true`, [more](./accounts.md#product-news)) |
| `Pictures__UploadsPerMinute` | Picture, logo and attachment uploads allowed per user per minute (default 10) |
| `Pictures__Gravatar` | `true` to show people's Gravatar when they haven't uploaded a picture (default `false`, [why](./accounts.md#profile-pictures)) |
| `Authentication__Google__ClientId`, `Authentication__Google__ClientSecret` | Optional: turns on "Continue with Google" ([how-to](./how-to/set-up-external-sign-in.md)) |
| `Authentication__GitHub__ClientId`, `Authentication__GitHub__ClientSecret` | Optional: turns on "Continue with GitHub" |
|  `Billing__Stripe__SecretKey`, `Billing__Stripe__WebhookSecret` | Optional: paid plans through Stripe ([billing](./billing.md#payments-with-stripe)) |
|  `Billing__Stripe__AutomaticTax` | `true` to have Stripe Tax add sales tax and VAT |
|  `Billing__TrialDays`, `Billing__TrialPlan` | The trial new organisations get (default 14 days of `pro`; 0 days turns it off) |

The app refuses to start outside Development if `Jwt:SigningKey` is missing, too short, or still
the development key, or if `App:ClientUrl` isn't set. Email links (confirmation, password reset,
invitations) are built from `App:ClientUrl`, never from the request's `Host` header: that header
is chosen by whoever sends the request, so a password reset requested with a forged host would
email a real link to someone else's site. Also refuse requests for other host names: the Caddy
setup in `deploy/` only serves `DOMAIN`, and without such a proxy set `AllowedHosts` (for example
`AllowedHosts=app.example.com`; keep your load balancer's health check host in it too).

The demo user is never created outside Development. Without
`Email:Smtp:Host`, no emails are sent and the app logs a warning instead (never the link), and
since new accounts must confirm their email, nobody can finish signing up: configure SMTP before
people register.

ASP.NET Core Data Protection keys, which protect the tokens in account emails, are stored in
PostgreSQL, so email links keep working across restarts and on every instance of the app.
:::

## Running more than one instance

The app is built to run as **one instance**, which a small server handles comfortably.

::: info With accounts
Some parts already work across several instances, because they coordinate through PostgreSQL:
Wolverine's outbox and scheduled messages, and the Data Protection keys.
:::

::: info Without accounts
Wolverine's outbox and scheduled messages already work across several instances, because they
coordinate through PostgreSQL.
:::

These parts don't yet:

* **Live updates (SignalR):** a message only reaches browsers connected to the instance that sent
  it. Several instances need a SignalR backplane (for example Redis).
* &#x20;**Rate limits** (sign-in, uploads, API keys): each instance counts separately, so the limits are multiplied by the number of instances. Shared limits need a shared store (for example Redis).
* &#x20;**Two-factor codes:** each instance remembers the codes used on it, so a code could be used once on each. Share the memory (a distributed cache) if that matters to you.
* &#x20;**Rate limits** (sign-in, uploads): each instance counts separately, so the limits are multiplied by the number of instances. Shared limits need a shared store (for example Redis).
* &#x20;**Two-factor codes:** each instance remembers the codes used on it, so a code could be used once on each. Share the memory (a distributed cache) if that matters to you.
* &#x20;**Data Protection keys,** which sign local storage's file URLs and upload tokens, are kept in each container: store them somewhere shared (`PersistKeysToDbContext`, a file share or a key vault) so a URL made by one instance works on another, and across restarts.
* &#x20;**In-memory state** you add yourself (caches, counters) is per instance.

Behind a CDN such as Cloudflare, one instance goes a long way, since the built client is served
from the CDN's cache; see [Put Cloudflare in front](./how-to/put-cloudflare-in-front.md).

Before going live, read the deployment checklist in [Security](./security.md#when-you-deploy).
