From d8c7bf1546d1e74563e865c29a454ca5f7caa3a4 Mon Sep 17 00:00:00 2001 From: Admin Date: Sat, 22 Nov 2025 18:24:54 +0200 Subject: [PATCH] add 2021 discord frontend support. i cant imagine hosting a web server and not using it proper use --- src/api/Server.ts | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/api/Server.ts b/src/api/Server.ts index 133e9dbb..107b60a4 100644 --- a/src/api/Server.ts +++ b/src/api/Server.ts @@ -22,6 +22,7 @@ import { Request, Response, Router } from "express"; import { Server, ServerOptions } from "lambert-server"; import morgan from "morgan"; import path from "path"; +import express from "express"; import { red } from "picocolors"; import { initInstance } from "./util/handlers/Instance"; @@ -90,18 +91,7 @@ export class SpacebarServer extends Server { await initTranslation(api); this.routes = await registerRoutes(this, path.join(__dirname, "routes", "/")); - - // 404 is not an error in express, so this should not be an error middleware - // this is a fine place to put the 404 handler because its after we register the routes - // and since its not an error middleware, our error handler below still works. - // Emma [it/its] @ Rory& - the _ is required now, as pillarjs throw an error if you don't pass a param name now - api.use("*_", (req: Request, res: Response) => { - res.status(404).json({ - message: "404 endpoint not found", - code: 0, - }); - }); - + this.app = app; //app.use("/__development", ) @@ -113,8 +103,8 @@ export class SpacebarServer extends Server { app.use("/api", api); // allow unversioned requests app.use("/imageproxy/:hash/:size/:url", ImageProxy); - - app.get("/", (req, res) => res.sendFile(path.join(PUBLIC_ASSETS_FOLDER, "index.html"))); + // for the 2021 discord frontend, can be replaced with anything else, just respect the way this file is structured + app.use("/assets", express.static(path.join(PUBLIC_ASSETS_FOLDER, "client"))); app.get("/verify-email", (req, res) => res.sendFile(path.join(PUBLIC_ASSETS_FOLDER, "verify.html"))); @@ -125,8 +115,10 @@ export class SpacebarServer extends Server { app.get("/_spacebar/api/openapi.json", (req, res) => { res.sendFile(path.join(ASSETS_FOLDER, "openapi.json")); }); - - // current well-known location + + app.use("*_", (req, res) => res.sendFile(path.join(PUBLIC_ASSETS_FOLDER, "index.html"))); + + // current well-known location (new commit 22 nov 2025 from spacebar) app.get("/.well-known/spacebar", (req,res)=>{ res.json({ api: Config.get().api.endpointPublic @@ -161,7 +153,7 @@ export class SpacebarServer extends Server { } }); }); - + this.app.use(ErrorHandler); ConnectionLoader.loadConnections();