summary refs log tree commit diff
path: root/bundle/src/Server.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-13 12:58:18 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-13 12:58:18 +0200
commit0802d5e6a849c822b7225423c8b20a38763ff45f (patch)
tree243de9b7ba8d54c94d8471dd4ac2ebf1293f1707 /bundle/src/Server.ts
parent:sparkles: docker compose (diff)
downloadserver-0802d5e6a849c822b7225423c8b20a38763ff45f.tar.xz
:sparkles: server bundle
Diffstat (limited to '')
-rw-r--r--bundle/src/Server.ts33
1 files changed, 33 insertions, 0 deletions
diff --git a/bundle/src/Server.ts b/bundle/src/Server.ts
new file mode 100644

index 00000000..14abc128 --- /dev/null +++ b/bundle/src/Server.ts
@@ -0,0 +1,33 @@ +process.on("unhandledRejection", console.error); +process.on("uncaughtException", console.error); + +import http from "http"; +import { FosscordServer as APIServer } from "@fosscord/api"; +import { Server as GatewayServer } from "@fosscord/gateway"; +import { CDNServer } from "@fosscord/cdn/"; +import express from "express"; +import { Config } from "../../util/dist"; + +const app = express(); +const server = http.createServer(); +const port = Number(process.env.PORT) || 8080; +const production = true; +server.on("request", app); + +// @ts-ignore +const api = new APIServer({ server, port, production, app }); +// @ts-ignore +const cdn = new CDNServer({ server, port, production, app }); +// @ts-ignore +const gateway = new GatewayServer({ server, port, production }); + +async function main() { + await api.start(); + await cdn.start(); + await gateway.start(); + + if (!Config.get().gateway.endpoint) await Config.set({ gateway: { endpoint: `ws://localhost:${port}` } }); + if (!Config.get().cdn.endpoint) await Config.set({ cdn: { endpoint: `http://localhost:${port}` } }); +} + +main().catch(console.error);