clonegur/backend/clonegur.ts

25 lines
778 B
TypeScript
Raw Normal View History

2023-06-29 14:31:25 +00:00
import { MongoClient } from "https://deno.land/x/mongo@v0.31.2/mod.ts";
import { RootRouter } from "./routers/RootRouter.ts";
import * as bcrypt from "https://deno.land/x/bcrypt@v0.4.1/mod.ts";
import AppDatabase from "./AppDatabase.ts";
export default async function clonegur() {
let salt;
try {
salt = new TextDecoder().decode(await Deno.readFile('keys/salt.txt'));
}
catch {
salt = await bcrypt.genSalt();
2023-06-30 00:37:07 +00:00
await Deno.mkdir('keys', { recursive: true });
2023-06-29 14:31:25 +00:00
await Deno.writeFile('keys/salt.txt', new TextEncoder().encode(salt));
}
const db = await new MongoClient().connect({
db: 'clonegur',
servers: [ { host: '127.0.0.1', port: 27017 } ]
});
return new RootRouter(salt, new AppDatabase(db));
}