2020-11-28 19:31:04 +01:00
|
|
|
import express, { Application, Router } from "express";
|
|
|
|
import { traverseDirectory } from "./Utils";
|
|
|
|
import { Server as HTTPServer } from "http";
|
|
|
|
import fs from "fs/promises";
|
2021-01-04 16:14:19 +01:00
|
|
|
import { Server, ServerOptions } from "lambert-server";
|
2020-11-28 19:31:04 +01:00
|
|
|
|
2021-01-04 16:14:19 +01:00
|
|
|
export interface DiscordServerOptions extends ServerOptions {}
|
2020-11-28 19:31:04 +01:00
|
|
|
|
2021-01-04 16:14:19 +01:00
|
|
|
declare global {
|
|
|
|
namespace Express {
|
|
|
|
interface Request {
|
|
|
|
server: DiscordServer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-28 19:31:04 +01:00
|
|
|
|
2021-01-04 16:14:19 +01:00
|
|
|
export class DiscordServer extends Server {
|
|
|
|
public options: DiscordServerOptions;
|
2020-11-28 19:31:04 +01:00
|
|
|
|
2021-01-04 16:14:19 +01:00
|
|
|
constructor(opts?: DiscordServerOptions) {
|
|
|
|
super(opts);
|
2020-11-28 19:31:04 +01:00
|
|
|
}
|
|
|
|
|
2021-01-04 16:14:19 +01:00
|
|
|
async start() {
|
2020-11-28 19:31:04 +01:00
|
|
|
// recursively loads files in routes/
|
|
|
|
this.routes = await this.registerRoutes(__dirname + "/routes/");
|
|
|
|
// const indexHTML = await (await fetch("https://discord.com/app")).buffer();
|
|
|
|
const indexHTML = await fs.readFile(__dirname + "/../client/index.html");
|
|
|
|
|
|
|
|
this.app.get("*", (req, res) => {
|
|
|
|
res.set("Cache-Control", "public, max-age=" + 60 * 60 * 24);
|
|
|
|
res.set("content-type", "text/html");
|
|
|
|
res.send(indexHTML);
|
|
|
|
});
|
2021-01-04 16:14:19 +01:00
|
|
|
return super.start();
|
2020-11-28 19:31:04 +01:00
|
|
|
}
|
|
|
|
}
|