Allow running api, cdn, gateway separately

This commit is contained in:
Madeline 2022-10-31 13:16:29 +11:00
parent ed92e2fa65
commit 49ae07ff29
5 changed files with 19 additions and 14 deletions

View File

@ -5,6 +5,9 @@
"scripts": { "scripts": {
"postinstall": "npx patch-package", "postinstall": "npx patch-package",
"start": "node dist/bundle/start.js", "start": "node dist/bundle/start.js",
"start:api": "node dist/api/start.js",
"start:cdn": "node dist/cdn/start.js",
"start:gateway": "node dist/gateway/start.js",
"build": "tsc -p .", "build": "tsc -p .",
"setup": "npm run build && npm run generate:schema", "setup": "npm run build && npm run generate:schema",
"generate:rights": "node scripts/rights.js", "generate:rights": "node scripts/rights.js",

View File

@ -1,7 +1,7 @@
import "missing-native-js-functions"; import "missing-native-js-functions";
import { Server, ServerOptions } from "lambert-server"; import { Server, ServerOptions } from "lambert-server";
import { Authentication, CORS } from "./middlewares/"; import { Authentication, CORS } from "./middlewares/";
import { Config, initDatabase, initEvent } from "@fosscord/util"; import { BannedWords, Config, initDatabase, initEvent } from "@fosscord/util";
import { ErrorHandler } from "./middlewares/ErrorHandler"; import { ErrorHandler } from "./middlewares/ErrorHandler";
import { BodyParser } from "./middlewares/BodyParser"; import { BodyParser } from "./middlewares/BodyParser";
import { Router, Request, Response, NextFunction } from "express"; import { Router, Request, Response, NextFunction } from "express";
@ -38,6 +38,7 @@ export class FosscordServer extends Server {
await Config.init(); await Config.init();
await initEvent(); await initEvent();
await initInstance(); await initInstance();
await BannedWords.init();
let logRequests = process.env["LOG_REQUESTS"] != undefined; let logRequests = process.env["LOG_REQUESTS"] != undefined;
if (logRequests) { if (logRequests) {

View File

@ -1,3 +1,4 @@
require("module-alias/register");
process.on("uncaughtException", console.error); process.on("uncaughtException", console.error);
process.on("unhandledRejection", console.error); process.on("unhandledRejection", console.error);

View File

@ -1,7 +1,7 @@
import "missing-native-js-functions"; import "missing-native-js-functions";
import dotenv from "dotenv"; import dotenv from "dotenv";
dotenv.config(); dotenv.config();
import { closeDatabase, Config, initDatabase, initEvent } from "@fosscord/util"; import { BannedWords, closeDatabase, Config, initDatabase, initEvent } from "@fosscord/util";
import ws from "ws"; import ws from "ws";
import { Connection } from "./events/Connection"; import { Connection } from "./events/Connection";
import http from "http"; import http from "http";
@ -50,6 +50,7 @@ export class Server {
await initDatabase(); await initDatabase();
await Config.init(); await Config.init();
await initEvent(); await initEvent();
await BannedWords.init();
if (!this.server.listening) { if (!this.server.listening) {
this.server.listen(this.port); this.server.listen(this.port);
console.log(`[Gateway] online on 0.0.0.0:${this.port}`); console.log(`[Gateway] online on 0.0.0.0:${this.port}`);

View File

@ -1,5 +1,5 @@
import amqp, { Connection, Channel } from "amqplib"; import amqp, { Connection, Channel } from "amqplib";
// import Config from "./Config"; import { Config } from "./Config";
export const RabbitMQ: { export const RabbitMQ: {
connection: Connection | null; connection: Connection | null;
@ -9,15 +9,14 @@ export const RabbitMQ: {
connection: null, connection: null,
channel: null, channel: null,
init: async function () { init: async function () {
return; const host = Config.get().rabbitmq.host;
// const host = Config.get().rabbitmq.host; if (!host) return;
// if (!host) return; console.log(`[RabbitMQ] connect: ${host}`);
// console.log(`[RabbitMQ] connect: ${host}`); this.connection = await amqp.connect(host, {
// this.connection = await amqp.connect(host, { timeout: 1000 * 60,
// timeout: 1000 * 60, });
// }); console.log(`[RabbitMQ] connected`);
// console.log(`[RabbitMQ] connected`); this.channel = await this.connection.createChannel();
// this.channel = await this.connection.createChannel(); console.log(`[RabbitMQ] channel created`);
// console.log(`[RabbitMQ] channel created`);
}, },
}; };