-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.ts
56 lines (47 loc) · 1.39 KB
/
mod.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
45
46
47
48
49
50
51
52
53
54
55
56
import { createApp } from "./src/app.ts";
import { lmdb } from "./src/deps.ts";
if (import.meta.main) {
const db = lmdb.open({
path: './colle.lmdb',
compression: true,
});
const pass = Deno.env.get("COLLE_ADMIN_PASS");
if (!pass) {
console.error("You need to set the admin password to use Colle.");
Deno.exit(1);
}
let cryptoKey = db.get(['crypto-key']);
if (!cryptoKey) {
console.log("Generating new key...");
const key = await crypto.subtle.generateKey(
{ name: "HMAC", hash: "SHA-512" },
true,
["sign", "verify"]
);
cryptoKey = await crypto.subtle.exportKey('raw', key);
await db.put(['crypto-key'], cryptoKey);
}
const env = (Deno.env.get("COLLE_ENV") || "PROD") as ("PROD" | "DEBUG");
const app = await createApp({
env,
db,
pass,
cryptoKey: await crypto.subtle.importKey(
'raw',
cryptoKey,
{ name: "HMAC", hash: "SHA-512" },
true,
["sign", "verify"]
)
});
const port = parseInt(Deno.env.get("COLLE_PORT") || '3000');
app.listen(port, (err) => {
if (err) {
console.error(err);
Deno.exit(1);
}
console.log("Listening on port", port);
})
}
import { Colle } from "./src/Colle.js";
export { Colle };