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

38 lines
1021 B
TypeScript
Raw Normal View History

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";
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
constructor(opts?: 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
}
}