Skip to content

Standalone & Docker ​

apps/server is the server without Nuxt: Nitro 3 with the core as its only handler, configured entirely by environment variables. It reports itself as mongocamp-nitro-server.

Docker ​

Build the image from the repository root:

bash
docker build -f apps/server/Dockerfile -t mongocamp-nitro-server .
docker run -p 8080:8080 -e CONNECTION_HOST=host.docker.internal mongocamp-nitro-server

The image is distroless Node 24 (about 214 MB, of which the server is 3 MB). Images for Bun and Deno are below. It stops cleanly on docker stop (SIGTERM) and on DELETE /system.

Docker Compose ​

yaml
services:
  mongodb:
    image: mongo:7
    volumes:
      - mongodb-data:/data/db

  mongocamp:
    image: mongocamp-nitro-server
    build:
      context: .
      dockerfile: apps/server/Dockerfile
    ports:
      - '8080:8080'
    environment:
      CONNECTION_HOST: mongodb
      CONNECTION_DATABASE: mongocamp
      CORS_ORIGINS_ALLOWED: '["http://localhost:3000"]'
      DOCS_SWAGGER: 'true'
    depends_on:
      - mongodb

volumes:
  mongodb-data:

Open http://localhost:8080/docs for the API reference. The password of the first user admin is printed to the log of the first start:

bash
docker compose logs mongocamp | grep -i password

Bun and Deno images ​

The same server also builds for Bun and Deno. The code, the API and the environment variables are identical; only the JavaScript runtime in the image differs.

DockerfileRuntimeNitro presetBase imageSize
apps/server/DockerfileNode 24node-server (default)gcr.io/distroless/nodejs24-debian12:nonroot~214 MB
apps/server/Dockerfile.bunBun 1.3bunoven/bun:1.3-distroless~169 MB
apps/server/Dockerfile.denoDeno 2.6deno_serverdenoland/deno:distroless-2.6.0~205 MB
bash
docker build -f apps/server/Dockerfile.bun -t mongocamp-nitro-server:bun .
docker build -f apps/server/Dockerfile.deno -t mongocamp-nitro-server:deno .

docker run -p 8080:8080 -e CONNECTION_HOST=host.docker.internal mongocamp-nitro-server:bun

How they work:

  • One build stage for all three. Each Dockerfile builds apps/server with Node 24 and pnpm, as the Node image does. The only difference is NITRO_PRESET, which tells Nitro which server entry to generate: Bun.serve for bun, Deno.serve for deno_server, node:http by default. The result is again a self-contained .output with no node_modules, copied into a distroless runtime image.
  • Non-root. The Bun and Deno base images run as root, so both Dockerfiles switch to the distroless nonroot user (65532).
  • Shutdown. docker stop (SIGTERM) and DELETE /system close the core and exit, as with Node. The Deno image runs under tini.
  • Deno permissions. The Deno image does not use -A. It grants only --allow-net (listener, MongoDB), --allow-env (configuration), --allow-read (the bundled files) and --allow-sys (OS info for the MongoDB handshake). Add flags in your own CMD if a declaration or plugin needs more, e.g. --allow-write.
  • Deno compatibility. Two Node behaviours are handled in the Deno image:
    • --unstable-bare-node-builtins: the MongoDB driver imports os without the node: prefix. Without the flag Deno rejects that import, the driver silently sends a handshake without client metadata, and MongoDB refuses every connection with Missing required sub-document 'driver'.
    • apps/server/deno-entry.mjs is the entry of the Deno image. It adds Node's BroadcastChannel#unref() (called by the metrics library at import time, missing in Deno) and then imports server/index.mjs.

Which one to use: the Node image is the reference. The contract and e2e suites run against Node, and it is what the Scala-compatible setup is verified with. Choose the Bun image for a smaller image and faster startup, or the Deno image when your platform standardizes on Deno or you want its permission sandbox. Test your own workload before you use either in production.

To use them in Docker Compose, set dockerfile: apps/server/Dockerfile.bun (or .deno) in the build section above.

Without Docker, the same presets work locally:

bash
NITRO_PRESET=bun pnpm --filter mongocamp-nitro-server build
bun run apps/server/.output/server/index.mjs

NITRO_PRESET=deno_server pnpm --filter mongocamp-nitro-server build
cp apps/server/deno-entry.mjs apps/server/.output/
deno run --allow-net --allow-env --allow-read --allow-sys --unstable-bare-node-builtins apps/server/.output/deno-entry.mjs

Without Docker ​

bash
pnpm install
pnpm --filter mongocamp-nitro-server build
CONNECTION_HOST=localhost node apps/server/.output/server/index.mjs

pnpm --filter mongocamp-nitro-server dev runs it with reload.

Logs ​

Every request is one JSON line on stdout, written by evlog, with the fields of the server under mongocamp (operation, user, collection, rows, error code). Collect them with the log driver of your platform. See Request Logging & Metrics.

json
{"method":"GET","path":"/mongodb/collections/books/documents","status":200,"durationMs":13,"mongocamp":{"operation":"listDocuments","user":"admin","collection":"books","rows":120},"level":"info","service":"mongocamp-nitro-server"}

Listener ​

The server listens on SERVER_INTERFACE:SERVER_PORT (default 0.0.0.0:8080). Nitro's NITRO_HOST/NITRO_PORT (or HOST/PORT) win.

Declared collections ​

apps/server/collections/index.ts exports the declared collections of the standalone server; plugins/collections.ts registers them. The list is empty; an image built from this app adds its declarations there (and the schema library to the dependencies of apps/server):

ts
// apps/server/collections/index.ts
import { z } from 'zod'
import { defineMongocampCollection } from '@sfxcode/mongocamp-server-core'

export const declarations = [
  defineMongocampCollection({
    name: 'orders',
    schema: z.object({ customer: z.string(), qty: z.int().min(1) }),
    validation: 'error',
  }),
]

Several instances ​

Instances can share a database. Users, roles, tokens, the token secret and the stored configurations live in it. Keep in mind:

  • Jobs run in every instance; there is no lock between instances. Set JOBS_ENABLED=false on all instances but one. The built-in token cleanup is also safe to run concurrently.
  • Events are delivered within the instance that handled the request.
  • Declared collections: every instance syncs the validators at its start; only the first one changes anything.
  • With AUTH_CACHE_DB, other instances keep their in-memory copy of a token for up to five minutes after it was revoked.

Upgrading ​

From an older MongoCamp server or image: see the migration guides.

Released under the MIT License.