mirror of
https://github.com/spacebarchat/server.git
synced 2026-05-25 12:04:39 +00:00
General work on API
This commit is contained in:
+9
-18
@@ -12,6 +12,7 @@ import { initTranslation } from "./middlewares/Translation";
|
||||
import morgan from "morgan";
|
||||
import { initInstance } from "./util/Instance";
|
||||
import { registerRoutes } from "@fosscord/util";
|
||||
import { red } from "nanocolors"
|
||||
|
||||
export interface FosscordServerOptions extends ServerOptions {}
|
||||
|
||||
@@ -38,17 +39,6 @@ export class FosscordServer extends Server {
|
||||
await initEvent();
|
||||
await initInstance();
|
||||
|
||||
/*
|
||||
DOCUMENTATION: uses LOG_REQUESTS environment variable
|
||||
|
||||
# only log 200 and 204
|
||||
LOG_REQUESTS=200 204
|
||||
# log everything except 200 and 204
|
||||
LOG_REQUESTS=-200 204
|
||||
# log all requests
|
||||
LOG_REQUESTS=-
|
||||
*/
|
||||
|
||||
let logRequests = process.env["LOG_REQUESTS"] != undefined;
|
||||
if (logRequests) {
|
||||
this.app.use(
|
||||
@@ -60,7 +50,7 @@ export class FosscordServer extends Server {
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
this.app.use(CORS);
|
||||
this.app.use(BodyParser({ inflate: true, limit: "10mb" }));
|
||||
@@ -85,19 +75,20 @@ export class FosscordServer extends Server {
|
||||
});
|
||||
|
||||
this.app = app;
|
||||
|
||||
//app.use("/__development", )
|
||||
//app.use("/__internals", )
|
||||
app.use("/api/v6", api);
|
||||
app.use("/api/v7", api);
|
||||
app.use("/api/v8", api);
|
||||
app.use("/api/v9", api);
|
||||
app.use("/api", api); // allow unversioned requests
|
||||
|
||||
this.app.use(ErrorHandler);
|
||||
TestClient(this.app);
|
||||
|
||||
if (logRequests) {
|
||||
console.log(
|
||||
"Warning: Request logging is enabled! This will spam your console!\nTo disable this, unset the 'LOG_REQUESTS' environment variable!"
|
||||
);
|
||||
}
|
||||
if (logRequests) console.log(red(`Warning: Request logging is enabled! This will spam your console!\nTo disable this, unset the 'LOG_REQUESTS' environment variable!`));
|
||||
|
||||
return super.start();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -3,25 +3,27 @@ import { HTTPError } from "lambert-server";
|
||||
import { checkToken, Config, Rights } from "@fosscord/util";
|
||||
|
||||
export const NO_AUTHORIZATION_ROUTES = [
|
||||
//Authentication routes
|
||||
// Authentication routes
|
||||
"/auth/login",
|
||||
"/auth/register",
|
||||
"/auth/location-metadata",
|
||||
//Routes with a seperate auth system
|
||||
// Routes with a seperate auth system
|
||||
"/webhooks/",
|
||||
//Public information endpoints
|
||||
// Public information endpoints
|
||||
"/ping",
|
||||
"/gateway",
|
||||
"/experiments",
|
||||
//Public kubernetes integration
|
||||
"/updates",
|
||||
"/downloads/",
|
||||
// Public kubernetes integration
|
||||
"/-/readyz",
|
||||
"/-/healthz",
|
||||
//Client nalytics
|
||||
// Client analytics
|
||||
"/science",
|
||||
"/track",
|
||||
//Public policy pages
|
||||
// Public policy pages
|
||||
"/policies/instance",
|
||||
//Asset delivery
|
||||
// Asset delivery
|
||||
/\/guilds\/\d+\/widget\.(json|png)/
|
||||
];
|
||||
|
||||
|
||||
@@ -88,7 +88,8 @@ export default function TestClient(app: Application) {
|
||||
res.set("Cache-Control", "public, max-age=" + 60 * 60 * 24);
|
||||
res.set("content-type", "text/html");
|
||||
|
||||
if(req.url.startsWith("/api")) return;
|
||||
if(req.url.startsWith("/api") || req.url.startsWith("/__development")) return;
|
||||
|
||||
if(!useTestClient) return res.send("Test client is disabled on this instance. Use a stand-alone client to connect this instance.")
|
||||
if (req.url.startsWith("/invite")) return res.send(html.replace("9b2b7f0632acd0c5e781", "9f24f709a3de09b67c49"));
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Router, Response, Request } from "express";
|
||||
import { route } from "@fosscord/api";
|
||||
import { Relase, Config } from "@fosscord/util";
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get("/:branch", route({}), async (req: Request, res: Response) => {
|
||||
const { client } = Config.get();
|
||||
const { branch } = req.params;
|
||||
const { platform } = req.query;
|
||||
|
||||
if(!platform || !["linux", "osx", "win"].includes(platform.toString())) return res.status(404)
|
||||
|
||||
const relase = await Relase.findOneOrFail({ name: client.relases.upstreamVersion });
|
||||
|
||||
res.redirect(relase[`win_url`]);
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Router, Response, Request } from "express";
|
||||
import { route } from "@fosscord/api";
|
||||
import { Config, Relase } from "@fosscord/util";
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||
const { client } = Config.get();
|
||||
|
||||
const relase = await Relase.findOneOrFail({ name: client.relases.upstreamVersion})
|
||||
|
||||
res.json({
|
||||
name: relase.name,
|
||||
pub_date: relase.pub_date,
|
||||
url: relase.url,
|
||||
notes: relase.notes
|
||||
});
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user