Implemented server routes

This commit is contained in:
Sebastian Seedorf
2022-08-17 23:27:19 +02:00
parent 9660f0cf34
commit 92b762bbd2
27 changed files with 2754 additions and 1692 deletions

View File

@@ -1,6 +1,7 @@
import {Db, MongoClient} from 'mongodb'
import {Collection, Db, MongoClient} from 'mongodb'
import getConfig from 'next/config'
import {Resolvable} from "../utils/Resolvable";
import {GroupData, InsertMeta} from "./groups";
const { serverRuntimeConfig: {
MONGO_URL,
@@ -9,12 +10,14 @@ const { serverRuntimeConfig: {
MONGO_DB
} } = getConfig()
async function getDatabase(): Promise<Db | undefined> {
async function getDatabase() {
const url = `mongodb://${MONGO_USER ? `${MONGO_USER}:${MONGO_PASS ?? ''}@` : ''}${MONGO_URL}`;
const client = new MongoClient(url);
await client.connect();
console.log('Connected successfully to server')
return client.db(MONGO_DB)
return client.db(MONGO_DB) as unknown as (Omit<Db, 'collection'> & {
collection : (_: 'setups') => Collection<InsertMeta<GroupData>>
})
}
export const database = new Resolvable(getDatabase)