Self Hosting (Custom)Database Adapters
MongoDB
Since v0.22.0+Build a self-hosted Hot Updater server with MongoDB.
Installation
Install the MongoDB native driver.
npm install @hot-updater/server @hot-updater/aws mongodb
npm install @hot-updater/bare @hot-updater/standalone hot-updater --save-devSetup
Create a database connection file:
import { MongoClient } from "mongodb";
export const client = new MongoClient(process.env.MONGODB_URI!);
// Connect to MongoDB
await client.connect();Hot Updater Configuration
Create the Hot Updater instance:
import { createHotUpdater } from "@hot-updater/server";
import { mongoAdapter } from "@hot-updater/server/adapters/mongodb";
import { s3Storage } from "@hot-updater/aws";
import { client } from "./mongodb";
export const hotUpdater = createHotUpdater({
database: mongoAdapter({ client }),
storages: [
s3Storage({
region: "auto",
endpoint: process.env.R2_ENDPOINT!,
credentials: {
accessKeyId: process.env.R2_ACCESS_KEY_ID!,
secretAccessKey: process.env.R2_SECRET_ACCESS_KEY!,
},
bucketName: process.env.R2_BUCKET_NAME!,
}),
],
basePath: "/hot-updater",
routes: { updateCheck: true, bundles: true },
});Protect /hot-updater/api/* with fail-closed authentication before mounting
the management routes. See Security Settings.
Schema Generation
Run the database migration to create the Hot Updater collections and indexes.
npx hot-updater db migrate src/hotUpdater.tsThis command targets src/hotUpdater.ts and creates every collection and index
required by the current Hot Updater schema.
CLI Configuration
Configure your CLI to use this self-hosted server.
import { bare } from "@hot-updater/bare";
import { s3Storage } from "@hot-updater/aws";
import { standaloneRepository } from "@hot-updater/standalone";
import { defineConfig } from "hot-updater";
const managementToken = process.env.HOT_UPDATER_AUTH_TOKEN;
if (!managementToken) {
throw new Error("HOT_UPDATER_AUTH_TOKEN is required");
}
export default defineConfig({
build: bare({ enableHermes: true }),
storage: s3Storage({
region: "auto",
endpoint: process.env.R2_ENDPOINT!,
credentials: {
accessKeyId: process.env.R2_ACCESS_KEY_ID!,
secretAccessKey: process.env.R2_SECRET_ACCESS_KEY!,
},
bucketName: process.env.R2_BUCKET_NAME!,
}),
database: standaloneRepository({
baseUrl: "http://localhost:3000/hot-updater",
commonHeaders: { Authorization: `Bearer ${managementToken}` },
}),
updateStrategy: "appVersion",
});The storage plugin must match the storages in your server's createHotUpdater. Both use s3Storage in this example.
API Endpoints
With the route groups enabled above, the server creates these endpoints:
| Method | Endpoint | Description |
|---|---|---|
| GET | /hot-updater/version | Get server version |
| GET | /hot-updater/fingerprint/:platform/:fingerprintHash/:channel/:minBundleId/:bundleId | Check for updates by fingerprint |
| GET | /hot-updater/app-version/:platform/:version/:channel/:minBundleId/:bundleId | Check for updates by app version |
| GET | /hot-updater/api/bundles | List bundles (query: channel, platform, limit, page, after, before) |
| GET | /hot-updater/api/bundles/:id | Get bundle by ID |
| POST | /hot-updater/api/bundles | Create bundles |
| PATCH | /hot-updater/api/bundles/:id | Update a bundle |
| DELETE | /hot-updater/api/bundles/:id | Delete bundle |
| GET | /hot-updater/api/bundles/channels | List all channels |