🎨 restructure gateway

This commit is contained in:
Flam3rboy 2021-10-02 15:12:47 +02:00
parent 66e2db8d88
commit 1716d92849
9 changed files with 36 additions and 12 deletions

View File

@ -58,7 +58,7 @@ function main() {
modify(definitions); modify(definitions);
fs.writeFileSync(schemaPath, JSON.stringify(definitions, null, 4).replace(/ "additionalProperties": ?false,?/g, "")); fs.writeFileSync(schemaPath, JSON.stringify(definitions, null, 4));
} }
main(); main();

View File

@ -38,9 +38,23 @@ async function main() {
'${location.protocol === "https:" ? "wss://" : "ws://"}${location.host}', '${location.protocol === "https:" ? "wss://" : "ws://"}${location.host}',
endpointPrivate: `ws://localhost:${port}`, endpointPrivate: `ws://localhost:${port}`,
...(!Config.get().gateway.endpointPublic && { ...(!Config.get().gateway.endpointPublic && {
endpointPublic: `http://localhost:${port}`, endpointPublic: `ws://localhost:${port}`,
}), }),
}, },
// regions: {
// default: "fosscord",
// useDefaultAsOptimal: true,
// available: [
// {
// id: "fosscord",
// name: "Fosscord",
// endpoint: "127.0.0.1:3001",
// vip: false,
// custom: false,
// deprecated: false,
// },
// ],
// },
} as any); } as any);
await Promise.all([api.start(), cdn.start(), gateway.start()]); await Promise.all([api.start(), cdn.start(), gateway.start()]);

View File

@ -4,7 +4,7 @@
"description": "", "description": "",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
"postinstall": "ts-patch install -s", "postinstall": "npx ts-patch install -s",
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"start": "npm run build && node dist/start.js", "start": "npm run build && node dist/start.js",
"build": "npx tsc -b .", "build": "npx tsc -b .",

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, RabbitMQ } from "@fosscord/util"; import { closeDatabase, Config, initDatabase, initEvent } from "@fosscord/util";
import { Server as WebSocketServer } from "ws"; import { Server as WebSocketServer } from "ws";
import { Connection } from "./events/Connection"; import { Connection } from "./events/Connection";
import http from "http"; import http from "http";
@ -12,15 +12,24 @@ export class Server {
public server: http.Server; public server: http.Server;
public production: boolean; public production: boolean;
constructor({ port, server, production }: { port: number; server?: http.Server; production?: boolean }) { constructor({
port,
server,
production,
}: {
port: number;
server?: http.Server;
production?: boolean;
}) {
this.port = port; this.port = port;
this.production = production || false; this.production = production || false;
if (server) this.server = server; if (server) this.server = server;
else else {
this.server = http.createServer(function (req, res) { this.server = http.createServer(function (req, res) {
res.writeHead(200).end("Online"); res.writeHead(200).end("Online");
}); });
}
this.server.on("upgrade", (request, socket, head) => { this.server.on("upgrade", (request, socket, head) => {
console.log("socket requests upgrade", request.url); console.log("socket requests upgrade", request.url);

View File

@ -35,8 +35,11 @@ export async function Connection(
// @ts-ignore // @ts-ignore
socket.encoding = searchParams.get("encoding") || "json"; socket.encoding = searchParams.get("encoding") || "json";
if (!["json", "etf"].includes(socket.encoding)) { if (!["json", "etf"].includes(socket.encoding)) {
if (socket.encoding === "etf" && erlpack) if (socket.encoding === "etf" && erlpack) {
throw new Error("Erlpack is not installed: 'npm i -D erlpack'"); throw new Error(
"Erlpack is not installed: 'npm i @yukikaze-bot/erlpack'"
);
}
return socket.close(CLOSECODES.Decode_error); return socket.close(CLOSECODES.Decode_error);
} }

View File

@ -1,7 +1,6 @@
import { Intents, Permissions } from "@fosscord/util"; import { Intents, Permissions } from "@fosscord/util";
import WS from "ws"; import WS from "ws";
import { Deflate } from "zlib"; import { Deflate } from "zlib";
import { Channel } from "amqplib";
export interface WebSocket extends WS { export interface WebSocket extends WS {
version: number; version: number;

View File

@ -1,5 +1,5 @@
export * from "./Constants"; export * from "./Constants";
export * from "./Send"; export * from "./Send";
export * from "./SessionUtils"; export * from "./SessionUtils";
export * from "./setHeartbeat"; export * from "./Heartbeat";
export * from "./WebSocket"; export * from "./WebSocket";

View File

@ -71,8 +71,7 @@
"baseUrl": ".", "baseUrl": ".",
"paths": { "paths": {
"@fosscord/gateway": ["src/index"], "@fosscord/gateway": ["src/index"],
"@fosscord/gateway/*": ["src/*"], "@fosscord/gateway/*": ["src/*"]
"@fosscord/util/*": ["../util/src/*"]
}, },
"plugins": [{ "transform": "@zerollup/ts-transform-paths" }] "plugins": [{ "transform": "@zerollup/ts-transform-paths" }]
} }