25 lines
778 B
TypeScript
25 lines
778 B
TypeScript
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();
|
|
await Deno.mkdir('keys', { recursive: true });
|
|
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));
|
|
}
|
|
|