summary refs log tree commit diff
path: root/src/api/Server.ts
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-08-30 15:05:23 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-08-30 15:08:18 +1000
commit16315a3170ec018a834e68360e06b506415446d2 (patch)
tree90cfe456040fce35b904e88462886e3c73a2f3f2 /src/api/Server.ts
parentStart listening after database and config has been loaded (diff)
parentOop, deprecated typeorm call (diff)
downloadserver-16315a3170ec018a834e68360e06b506415446d2.tar.xz
Merge branch 'staging' into dev/Maddy/fix/listeningAfterDb
Diffstat (limited to '')
-rw-r--r--src/api/Server.ts (renamed from api/src/Server.ts)31
1 files changed, 17 insertions, 14 deletions
diff --git a/api/src/Server.ts b/src/api/Server.ts

index 4cf0917d..e92335a5 100644 --- a/api/src/Server.ts +++ b/src/api/Server.ts
@@ -1,18 +1,16 @@ -import "missing-native-js-functions"; +import { Config, getOrInitialiseDatabase, initEvent, registerRoutes } from "@fosscord/util"; +import { NextFunction, Request, Response, Router } from "express"; import { Server, ServerOptions } from "lambert-server"; +import morgan from "morgan"; +import path from "path"; +import { red } from "picocolors"; import { Authentication, CORS } from "./middlewares/"; -import { Config, initDatabase, initEvent } from "@fosscord/util"; -import { ErrorHandler } from "./middlewares/ErrorHandler"; import { BodyParser } from "./middlewares/BodyParser"; -import { Router, Request, Response, NextFunction } from "express"; -import path from "path"; +import { ErrorHandler } from "./middlewares/ErrorHandler"; import { initRateLimits } from "./middlewares/RateLimit"; import TestClient from "./middlewares/TestClient"; import { initTranslation } from "./middlewares/Translation"; -import morgan from "morgan"; import { initInstance } from "./util/handlers/Instance"; -import { registerRoutes } from "@fosscord/util"; -import { red } from "picocolors" export interface FosscordServerOptions extends ServerOptions {} @@ -34,7 +32,7 @@ export class FosscordServer extends Server { } async start() { - await initDatabase(); + await getOrInitialiseDatabase(); await Config.init(); await initEvent(); await initInstance(); @@ -44,13 +42,13 @@ export class FosscordServer extends Server { this.app.use( morgan("combined", { skip: (req, res) => { - var skip = !(process.env["LOG_REQUESTS"]?.includes(res.statusCode.toString()) ?? false); + let skip = !(process.env["LOG_REQUESTS"]?.includes(res.statusCode.toString()) ?? false); if (process.env["LOG_REQUESTS"]?.charAt(0) == "-") skip = !skip; return skip; } }) ); - }; + } this.app.use(CORS); this.app.use(BodyParser({ inflate: true, limit: "10mb" })); @@ -87,8 +85,13 @@ export class FosscordServer extends Server { this.app.use(ErrorHandler); TestClient(this.app); - if (logRequests) console.log(red(`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(); } -}; \ No newline at end of file +}