-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
44 lines (39 loc) · 1.47 KB
/
index.ts
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
#!/usr/bin/env node
import { config, publicKeys } from "./src/config.js";
import { name, version } from "./package.json" assert { type: "json" };
import DELETE from "./src/fetch/DELETE.js";
import GET from "./src/fetch/GET.js";
import OPTIONS from "./src/fetch/OPTIONS.js";
import POST from "./src/fetch/POST.js";
import PUT from "./src/fetch/PUT.js";
import { NotFound } from "./src/fetch/cors.js";
import { logger } from "./src/logger.js";
import init from "./src/fetch/init.js";
import { show_databases, show_tables } from "./src/clickhouse/stores.js";
import "./src/exitHandler.js"
import * as buffer from "./src/buffer.js"
if (config.verbose) logger.enable();
// initizalize before starting the server
await init();
await show_tables();
await show_databases();
await buffer.flush(true);
const app = Bun.serve({
hostname: config.hostname,
port: config.port,
fetch(req: Request) {
if (req.method === "GET") return GET(req);
if (req.method === "POST") return POST(req);
if (req.method === "PUT") return PUT(req);
if (req.method === "OPTIONS") return OPTIONS(req);
if (req.method === "DELETE") return DELETE(req);
return NotFound;
},
});
// logging
logger.info('[app]\t', `${name} v${version}`);
logger.info('[app]\t', `Sink Server listening on http://${app.hostname}:${app.port}`);
logger.info('[app]\t', `Clickhouse DB ${config.host} (${config.database})`);
for ( const publicKey of publicKeys ) {
logger.info('[app]\t', `Webhook Ed25519 public key (${publicKey})`);
}