summary refs log tree commit diff
path: root/bundle/src/Server.ts
blob: 68966bf4e6636f769907d79c80070e00e2c3b88a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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(app);
const port = Number(process.env.PORT) || 8080;
const production = true;

// @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 Config.set({
		cdn: { endpointClientKeepDefault: true, endpoint: `http://localhost:${port}` },
		gateway: { endpointClientKeepDefault: true, endpoint: `ws://localhost:${port}` },
	});

	await api.start();
	await cdn.start();
	await gateway.start();
}

main().catch(console.error);