diff options
author | Chris Chrome <christophercookman@gmail.com> | 2021-12-26 13:38:25 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-26 13:38:25 -0500 |
commit | 565f3b9e5f067745dfb4339b621973c9c39bb690 (patch) | |
tree | b601211fedf84401165b0e8626cf3fec1fc88db1 /bundle/src/Server.ts | |
parent | Fix the casing (diff) | |
parent | Add env name in sentry, set default sentry endpoint (diff) | |
download | server-565f3b9e5f067745dfb4339b621973c9c39bb690.tar.xz |
Merge pull request #553 from TheArcaneBrony/master
Remove fs-extras, add Sentry support, fix compile errors, fix some typos
Diffstat (limited to 'bundle/src/Server.ts')
-rw-r--r-- | bundle/src/Server.ts | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/bundle/src/Server.ts b/bundle/src/Server.ts index c5da5fc9..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(); @@ -64,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)}`)}`); } |