main.ts

1.0 KB · raw

1import { join } from "node:path";2import { openBucket } from "./bucket/reader.ts";3import { startSyncLoop } from "./bucket/sync.ts";4import { createApp } from "./server/app.ts";5import { startBackupLoop } from "./server/backup.ts";6import { CONFIG_FILE, ConfigError, loadConfig } from "./server/config.ts";7import { openKeprDb } from "./server/db.ts";89try {10	const config = await loadConfig(CONFIG_FILE);11	const kepr = openKeprDb(config.dataDir);12	// One bucket for the sync loop and the app, so settings saved in the console reach both.13	const bucket = openBucket(config.bucket);14	startBackupLoop(kepr, config.dataDir);15	startSyncLoop({16		bucket,17		kepr,18		mirrorDir: join(config.dataDir, "mirror"),19		tarballDir: join(config.dataDir, "tarballs"),20	});21	// Bun.serve reads the port from $PORT (default 3000).22	const server = Bun.serve({ fetch: createApp(config, kepr, bucket).fetch });23	console.log(`kepr listening on ${server.url}`);24} catch (error) {25	if (!(error instanceof ConfigError)) throw error;26	console.error(`kepr: ${error.message}`);27	process.exit(1);28}