2020-12-30 22:49:01 +01:00
|
|
|
import { MongoDatabase, Database } from "lambert-db";
|
2021-01-04 16:10:12 +01:00
|
|
|
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 {
|
2021-01-04 16:10:12 +01:00
|
|
|
cdn: CDNServer;
|
2020-12-30 22:49:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 16:10:12 +01:00
|
|
|
export interface CDNServerOptions extends ServerOptions {
|
|
|
|
db: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class CDNServer extends Server {
|
2020-12-30 22:49:01 +01:00
|
|
|
db: Database;
|
2021-01-04 16:10:12 +01:00
|
|
|
public options: CDNServerOptions;
|
|
|
|
|
2021-05-10 18:04:02 +02:00
|
|
|
constructor(options: Partial<CDNServerOptions>) {
|
2021-01-04 16:10:12 +01:00
|
|
|
super(options);
|
2020-12-30 22:49:01 +01:00
|
|
|
|
|
|
|
this.db = new MongoDatabase(options?.db);
|
|
|
|
}
|
|
|
|
|
2021-01-04 16:10:12 +01:00
|
|
|
async start() {
|
|
|
|
console.log("[Database] connecting ...");
|
2020-12-30 22:49:01 +01:00
|
|
|
await this.db.init();
|
2021-01-04 16:10:12 +01:00
|
|
|
console.log("[Database] connected");
|
|
|
|
return super.start();
|
2020-12-30 22:49:01 +01:00
|
|
|
}
|
|
|
|
|
2021-01-04 16:10:12 +01:00
|
|
|
async stop() {
|
2020-12-30 22:49:01 +01:00
|
|
|
await this.db.destroy();
|
2021-01-04 16:10:12 +01:00
|
|
|
return super.stop();
|
2020-12-30 22:49:01 +01:00
|
|
|
}
|
|
|
|
}
|