3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 20:35:02 +00:00

dashboard/api: add support for Zeppelin staff members; add ViewGuild permission; code cleanup

This commit is contained in:
Dragory 2020-05-23 16:22:03 +03:00
parent 7e60950900
commit d03d729438
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
13 changed files with 175 additions and 75 deletions

View file

@ -1,14 +1,5 @@
import { clientError, error, notFound } from "./responses";
import express from "express";
import cors from "cors";
import { initAuth } from "./auth";
import { initGuildsAPI } from "./guilds";
import { initArchives } from "./archives";
import { initDocs } from "./docs";
import { connect } from "../data/db";
import path from "path";
import { TokenError } from "passport-oauth2";
import { PluginError } from "knub";
require("dotenv").config({ path: path.resolve(process.cwd(), "api.env") });
@ -19,43 +10,8 @@ function errorHandler(err) {
process.on("unhandledRejection", errorHandler);
// Connect to the database before loading the rest of the code (that depend on the database connection)
console.log("Connecting to database..."); // tslint:disable-line
connect().then(() => {
const app = express();
app.use(
cors({
origin: process.env.DASHBOARD_URL,
}),
);
app.use(express.json());
initAuth(app);
initGuildsAPI(app);
initArchives(app);
initDocs(app);
// Default route
app.get("/", (req, res) => {
res.json({ status: "cookies", with: "milk" });
});
// Error response
app.use((err, req, res, next) => {
if (err instanceof TokenError) {
clientError(res, "Invalid code");
} else {
console.error(err); // tslint:disable-line
error(res, "Server error", err.status || 500);
}
});
// 404 response
app.use((req, res, next) => {
return notFound(res);
});
const port = process.env.PORT || 3000;
// tslint:disable-next-line
app.listen(port, () => console.log(`API server listening on port ${port}`));
import("./start");
});