-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
44 lines (36 loc) · 1.07 KB
/
server.ts
File metadata and controls
44 lines (36 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { ensureConfigDir, booksDbPath, port } from "./src/config";
import { openDatabase } from "./src/db";
import { createPodibleFetchHandler } from "./src/http";
import { BooksRepo } from "./src/repo";
import { runWorker } from "./src/worker";
const startTime = Date.now();
await ensureConfigDir();
const db = openDatabase(booksDbPath);
const repo = new BooksRepo(db);
repo.ensureSettings();
const current = repo.getSettings();
void runWorker({
repo,
getSettings: () => repo.getSettings(),
onLog: (message) => console.log(message),
});
const server = Bun.serve({
port,
idleTimeout: 60,
fetch: createPodibleFetchHandler(repo, startTime),
});
const localBase = `http://localhost${port === 80 ? "" : `:${port}`}`;
console.log(`Podible backend listening on ${localBase}`);
console.log(`Library root: ${current.libraryRoot}`);
console.log(`RPC endpoint: ${localBase}/rpc`);
console.log(`Home: ${localBase}/`);
process.on("SIGINT", () => {
server.stop();
db.close();
process.exit(0);
});
process.on("SIGTERM", () => {
server.stop();
db.close();
process.exit(0);
});