How production works

Carnival3 is Bun-only and has no build step. Modules are discovered at startup from modules/*/init.ts and imported directly as TypeScript, so production runs the same source you develop with:

bun run start   # = bun server.ts

Because modules, templates, themes, and widgets are read from disk at runtime, deploy the whole project folder (not a bundle). bun build --compile single-file binaries are not supported for the same reason.

Prerequisites

  • A Linux server (VPS) with Bun 1.1+ installed
  • A domain pointing at the server
  • A .env file with production values (see .env.example)

On Render: see Deploy on Render (Blueprint, persistent disk, local SQLite).

As static files only (no server for the site itself): see Deploy as a ZIP (export, static hosts, XAMPP).

Static hosting instead: a site can also be exported as plain HTML, CSS and JS (Admin > Sites, the download button) and uploaded to any static host. The Carnival3 server then only needs to be reachable for the admin and the contact form. See How to create a site, "Export as a Static Site".

1. Install the app

git clone <your-repo> /srv/my-app
cd /srv/my-app
bun install --production
cp .env.example .env   # then edit production values

Minimum production .env:

PORT=3000
APP_ENV=production
APP_URL="https://yourdomain.com"
TURSO_DATABASE_URL="file:local.db"      # or libsql://your-db.turso.io
TURSO_AUTH_TOKEN=""                     # required for Turso Cloud
LOG_LEVEL=ERROR
CACHE_ENABLED=true

Start it once by hand to create the database, then sign in and change the default admin password (test@c3.com / 123456).

bun run start

2. Keep it running

Use either PM2 or systemd, not both.

Option A: PM2

bun add -g pm2
pm2 start server.ts --name my-app --interpreter bun
pm2 save
pm2 startup   # follow the printed command to start on boot

Or with a config file, ecosystem.config.cjs:

module.exports = {
  apps: [
    {
      name: 'my-app',
      script: 'server.ts',
      interpreter: 'bun',
      cwd: '/srv/my-app',
      autorestart: true,
      max_memory_restart: '512M',
    },
  ],
};

Settings come from .env, which Bun loads automatically from the working directory.

Run one process (no PM2 cluster mode, no several instances behind a load balancer): the page cache index, the settings memo, the active-site cache and the rate limiter live in the process's memory.

Option B: systemd

Create /etc/systemd/system/my-app.service:

[Unit]
Description=my-app (Carnival3)
After=network.target

[Service]
Type=simple
User=www-data
WorkingDirectory=/srv/my-app
ExecStart=/usr/local/bin/bun server.ts
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now my-app
journalctl -u my-app -f   # follow output

The service user needs write access to cache/, logs/, uploads/, uploaded-themes/ (themes added, duplicated or edited in Admin > Themes; set UPLOADED_THEMES_DIR to keep it elsewhere), widgets/ (widget type uploads), modules/site/ (new sites) and the SQLite file if you use a local database.

3. Put a reverse proxy in front

The app listens on plain HTTP. Terminate TLS with a reverse proxy. With Caddy (automatic HTTPS), the whole Caddyfile is:

yourdomain.com {
    reverse_proxy localhost:3000
}

With Nginx:

location / {
    proxy_pass http://localhost:3000;
    proxy_set_header Host $host;
    # Replace (not append) so visitors can't fake their IP; the rate limiter uses it
    proxy_set_header X-Forwarded-For $remote_addr;
}

Keep port 3000 closed to the internet so all traffic goes through the proxy. The rate limiter (sign-in, registration, email verification, password reset, contact form) identifies visitors by X-Forwarded-For, so it must come from the proxy.

Behind a proxy or CDN that sends the real address in its own header (Cloudflare's CF-Connecting-IP, Render's True-Client-IP), set CLIENT_IP_HEADER to that header name in .env instead; it is read before X-Forwarded-For.

4. Updating

cd /srv/my-app
git pull
bun install --production
pm2 restart my-app        # or: sudo systemctl restart my-app

Module schema changes are applied automatically on startup, and cached pages are cleared on startup, so visitors see new templates right after the restart. Browsers keep theme CSS and JS for up to a day.

Without shell access to restart, use Admin > Modules > Restart server (administrators): it lists the module code that changed since the start, waits for requests in progress, exits, and PM2 or systemd (Restart=always, as above) starts the server again. It is offered only when PM2 or systemd is detected or RESTART_SUPPORTED=true is set in .env (for example Docker with a restart policy), and is refused while a long task (static export, media upload or sync) is running.

5. Files created on the server

Some things are created through the admin and exist only on the server, not in git:

  • Themes added in Admin > Themes (uploaded-themes/<name>/, apart from the code, with earlier file versions in uploaded-themes/.history/), widget types uploaded as ZIPs (widgets/<type>/), and site assets and media (uploads/).
  • Sites added in Admin > Sites create modules/site/<name>/init.ts. Before adding custom code to it, copy that file into your repository so it is deployed with the rest of the code.

Back these up with the database, or commit the themes you want to keep.

Production checklist

  • Staging copies: turn off Allow search engines (Settings > SEO & Analytics) so they are not indexed.
  • Settings > Cache overrides CACHE_ENABLED once it has been saved; Settings > System shows what .env contains.
  • APP_ENV=production: error pages show no stack traces (they appear with development).
  • APP_URL set to the public HTTPS URL (used for links in password-reset and verification emails, the sitemap, and robots.txt).
  • If Require Email Verification is on, email is set up and a test email (Admin > Settings > Email Service > Test Email) arrives; without email, registration and password reset are refused.
  • Default admin password changed.
  • Email configured in Admin > Settings > Email and the active site's contact email set in Admin > Sites, so the contact form works.
  • Back up the database, uploads/, uploaded-themes/ and any uploaded widget types. Turso Cloud provides managed backups; for a local SQLite file, run bun run cli db:backup on a schedule (a consistent copy, safe while the app runs; a plain cp of the open file may not be).
  • Error alerts: with email working, administrators get an email when errors pile up (Admin > Settings > Error Alerts; default 10 errors in 5 minutes). Check the recipients there. For downtime, point an uptime monitor at /health (it answers 503 when the database fails). Admin > System > Server Status shows memory, CPU, response times, errors and disk space with graphs; it cannot report its own downtime.
  • cache/ and logs/ are disposable and can be deleted at any time.