1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-14 22:52:41 +01:00
server/src/Server.ts

43 lines
827 B
TypeScript
Raw Normal View History

2020-12-30 22:49:01 +01:00
import { MongoDatabase, Database } from "lambert-db";
import { Server, ServerOptions } from "lambert-server";
2020-12-30 22:49:01 +01:00
const log = console.log;
console.log = (content) => {
log(`[${new Date().toTimeString().split(" ")[0]}]`, content);
};
declare global {
namespace Express {
interface Request {
cdn: CDNServer;
2020-12-30 22:49:01 +01:00
}
}
}
export interface CDNServerOptions extends ServerOptions {
db: string;
}
export class CDNServer extends Server {
2020-12-30 22:49:01 +01:00
db: Database;
public options: CDNServerOptions;
2021-05-10 18:04:02 +02:00
constructor(options: Partial<CDNServerOptions>) {
super(options);
2020-12-30 22:49:01 +01:00
this.db = new MongoDatabase(options?.db);
}
async start() {
console.log("[Database] connecting ...");
2020-12-30 22:49:01 +01:00
await this.db.init();
console.log("[Database] connected");
return super.start();
2020-12-30 22:49:01 +01:00
}
async stop() {
2020-12-30 22:49:01 +01:00
await this.db.destroy();
return super.stop();
2020-12-30 22:49:01 +01:00
}
}