1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-09-22 10:41:34 +02:00
server/src/Server.ts

35 lines
884 B
TypeScript
Raw Normal View History

2020-11-28 19:31:04 +01:00
import fs from "fs/promises";
import { Server, ServerOptions } from "lambert-server";
2020-11-28 19:31:04 +01:00
export interface DiscordServerOptions extends ServerOptions {}
2020-11-28 19:31:04 +01:00
declare global {
namespace Express {
interface Request {
server: DiscordServer;
}
}
}
2020-11-28 19:31:04 +01:00
export class DiscordServer extends Server {
public options: DiscordServerOptions;
2020-11-28 19:31:04 +01:00
2021-01-04 16:29:49 +01:00
constructor(opts?: Partial<DiscordServerOptions>) {
super(opts);
2020-11-28 19:31:04 +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);
});
return super.start();
2020-11-28 19:31:04 +01:00
}
}