summary refs log tree commit diff
path: root/bundle/src
diff options
context:
space:
mode:
Diffstat (limited to 'bundle/src')
-rw-r--r--bundle/src/Server.ts37
-rw-r--r--bundle/src/start.ts6
-rw-r--r--bundle/src/stats.ts2
3 files changed, 40 insertions, 5 deletions
diff --git a/bundle/src/Server.ts b/bundle/src/Server.ts

index e461ec5f..71a60d49 100644 --- a/bundle/src/Server.ts +++ b/bundle/src/Server.ts
@@ -6,8 +6,10 @@ import * as Api from "@fosscord/api"; import * as Gateway from "@fosscord/gateway"; import { CDNServer } from "@fosscord/cdn"; import express from "express"; -import { green, bold } from "nanocolors"; +import { green, bold, yellow } from "picocolors"; import { Config, initDatabase } from "@fosscord/util"; +import * as Sentry from "@sentry/node"; +import * as Tracing from "@sentry/tracing"; const app = express(); const server = http.createServer(); @@ -22,6 +24,14 @@ const cdn = new CDNServer({ server, port, production, app }); // @ts-ignore const gateway = new Gateway.Server({ server, port, production }); +//this is what has been added for the /stop API route +process.on('SIGTERM', () => { + server.close(() => { + console.log("Stop API has been successfully POSTed, SIGTERM sent") + }) +}) +//this is what has been added for the /stop API route + async function main() { server.listen(port); await initDatabase(); @@ -56,7 +66,32 @@ async function main() { // }, } as any); + //Sentry + if (Config.get().sentry.enabled) { + console.log( + `[Bundle] ${yellow("You are using Sentry! This may slightly impact performance on large loads!")}` + ); + Sentry.init({ + dsn: Config.get().sentry.endpoint, + integrations: [ + new Sentry.Integrations.Http({ tracing: true }), + new Tracing.Integrations.Express({ app }), + ], + tracesSampleRate: Config.get().sentry.traceSampleRate, + environment: Config.get().sentry.environment + }); + + app.use(Sentry.Handlers.requestHandler()); + app.use(Sentry.Handlers.tracingHandler()); + } await Promise.all([api.start(), cdn.start(), gateway.start()]); + if (Config.get().sentry.enabled) { + app.use(Sentry.Handlers.errorHandler()); + app.use(function onError(err: any, req: any, res: any, next: any) { + res.statusCode = 500; + res.end(res.sentry + "\n"); + }); + } console.log(`[Server] ${green(`listening on port ${bold(port)}`)}`); } diff --git a/bundle/src/start.ts b/bundle/src/start.ts
index 8725ba61..7660b296 100644 --- a/bundle/src/start.ts +++ b/bundle/src/start.ts
@@ -2,7 +2,7 @@ import "reflect-metadata"; import cluster, { Worker } from "cluster"; import os from "os"; -import { red, bold, yellow, cyan } from "nanocolors"; +import { red, bold, yellow, cyan } from "picocolors"; import { initStats } from "./stats"; import { config } from "dotenv"; config(); @@ -31,7 +31,7 @@ if (cluster.isMaster) { ╚═╝ ╚═════╝ ╚══════╝╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═════╝ fosscord-server | ${yellow( - `Pre-relase (${ + `Pre-release (${ commit !== null ? commit.slice(0, 7) : "Unknown (Git cannot be found)" @@ -43,7 +43,7 @@ Commit Hash: ${ ? `${cyan(commit)} (${yellow(commit.slice(0, 7))})` : "Unknown (Git cannot be found)" } -Cores: ${cyan(cores)} +Cores: ${cyan(os.cpus().length)} (Using ${cores} thread(s).) `) ); diff --git a/bundle/src/stats.ts b/bundle/src/stats.ts
index 8d87f9d9..3c5163c3 100644 --- a/bundle/src/stats.ts +++ b/bundle/src/stats.ts
@@ -1,6 +1,6 @@ import os from "os"; import osu from "node-os-utils"; -import { red } from "nanocolors"; +import { red } from "picocolors"; export function initStats() { console.log(`[Path] running in ${__dirname}`);