1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-05 10:22:31 +01:00

🚧 fix server bundle

This commit is contained in:
Flam3rboy 2021-08-13 22:57:46 +02:00
parent f70a24ab6a
commit 194ef5478e
10 changed files with 96 additions and 28 deletions

View File

@ -0,0 +1,10 @@
import { Router, Response, Request } from "express";
const router = Router();
router.post("/", (req: Request, res: Response) => {
// TODO:
res.sendStatus(204);
});
export default router;

18
bundle/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"sourceMaps": true,
"type": "node",
"request": "launch",
"name": "Launch server bundle",
"program": "${workspaceFolder}/dist/start.js",
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"envFile": "${workspaceFolder}/.env"
}
]
}

View File

@ -7,6 +7,7 @@
"": {
"name": "@fosscord/server",
"version": "1.0.0",
"hasInstallScript": true,
"license": "AGPLV3",
"dependencies": {
"@fosscord/api": "file:../api",
@ -28,7 +29,6 @@
"../api": {
"name": "@fosscord/api",
"version": "1.0.0",
"hasInstallScript": true,
"license": "ISC",
"dependencies": {
"@fosscord/util": "file:../util",
@ -85,7 +85,6 @@
"../cdn": {
"name": "@fosscord/cdn",
"version": "1.0.0",
"hasInstallScript": true,
"license": "ISC",
"dependencies": {
"@fosscord/util": "file:../util",
@ -121,7 +120,6 @@
"../gateway": {
"name": "@fosscord/gateway",
"version": "1.0.0",
"hasInstallScript": true,
"license": "ISC",
"dependencies": {
"@fosscord/util": "file:../util",
@ -152,7 +150,13 @@
"version": "1.3.55",
"hasInstallScript": true,
"license": "GPLV3",
"dependencies": {
"devDependencies": {
"@types/amqplib": "^0.8.1",
"@types/jsonwebtoken": "^8.5.0",
"@types/mongodb": "^3.6.9",
"@types/mongoose-autopopulate": "^0.10.1",
"@types/mongoose-lean-virtuals": "^0.5.1",
"@types/node": "^14.17.9",
"ajv": "^8.5.0",
"amqplib": "^0.8.0",
"dot-prop": "^6.0.1",
@ -161,15 +165,7 @@
"missing-native-js-functions": "^1.2.2",
"mongodb": "^3.6.9",
"mongoose": "^5.13.7",
"mongoose-autopopulate": "^0.12.3"
},
"devDependencies": {
"@types/amqplib": "^0.8.1",
"@types/jsonwebtoken": "^8.5.0",
"@types/mongodb": "^3.6.9",
"@types/mongoose-autopopulate": "^0.10.1",
"@types/mongoose-lean-virtuals": "^0.5.1",
"@types/node": "^14.17.9",
"mongoose-autopopulate": "^0.12.3",
"typescript": "^4.1.3"
}
},

View File

@ -4,7 +4,7 @@
"description": "",
"main": "src/start.js",
"scripts": {
"postinstall": "cd ../api/ && npm i && cd ../cdn/ && npm i && cd ../gateway/ && npm i && ",
"postinstall": "cd ../api/ && npm i && cd ../cdn/ && npm i && cd ../gateway/ && npm i",
"build": "npm run build:api && npm run build:cdn && npm run build:gateway && npm run build:bundle",
"build:bundle": "tsc -b .",
"build:api": "cd ../api/ && npm run build",

View File

@ -9,9 +9,10 @@ import express from "express";
import { Config } from "../../util/dist";
const app = express();
const server = http.createServer(app);
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 });
@ -22,8 +23,14 @@ 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}` },
cdn: {
endpointClient: "${location.host}",
endpoint: `http://localhost:${port}`,
},
gateway: {
endpointClient: '${location.protocol === "https:" ? "wss://" : "ws://"}${location.host}',
endpoint: `ws://localhost:${port}`,
},
});
await api.start();

View File

@ -0,0 +1,29 @@
{
"folders": [
{
"path": "api"
},
{
"path": "dashboard"
},
{
"path": "bundle"
},
{
"path": "cdn"
},
{
"path": "gateway"
},
{
"path": "rtc"
},
{
"path": "util"
},
{
"path": "webrtc"
}
],
"settings": {}
}

View File

@ -23,6 +23,8 @@ export class Server {
});
this.server.on("upgrade", (request, socket, head) => {
console.log("socket requests upgrade", request.url);
// @ts-ignore
this.ws.handleUpgrade(request, socket, head, (socket) => {
this.ws.emit("connection", socket, request);
});

View File

@ -58,13 +58,14 @@ export async function setupListener(this: WebSocket) {
this.permissions[guild] = x;
this.listeners;
this.events[guild] = await listenEvent(guild, consumer, opts);
for (const channel of guild_channels) {
for (const channel of guild_channels.filter((c) => c.guild_id === guild)) {
if (x.overwriteChannel(channel.permission_overwrites).has("VIEW_CHANNEL")) {
this.events[channel.id] = await listenEvent(channel.id, consumer, opts);
}
}
})
.catch((e) => {});
.catch((e) => console.log("couldn't get permission for guild " + guild, e));
}
this.once("close", () => {
@ -74,14 +75,14 @@ export async function setupListener(this: WebSocket) {
}
// TODO: only subscribe for events that are in the connection intents
function consume(this: WebSocket, opts: EventOpts) {
async function consume(this: WebSocket, opts: EventOpts) {
const { data, event } = opts;
const id = data.id as string;
const permission = this.permissions[id] || new Permissions("ADMINISTRATOR"); // default permission for dm
const consumer = consume.bind(this);
const listenOpts = opts as ListenEventOpts;
console.log("event", event);
// console.log("event", event);
// subscription managment
switch (event) {
@ -94,14 +95,14 @@ function consume(this: WebSocket, opts: EventOpts) {
if (!permission.overwriteChannel(data.permission_overwrites).has("VIEW_CHANNEL")) return;
// TODO: check if user has permission to channel
case "GUILD_CREATE":
listenEvent(id, consumer, listenOpts);
this.events[id] = await listenEvent(id, consumer, listenOpts);
break;
case "CHANNEL_UPDATE":
const exists = this.events[id];
// @ts-ignore
if (permission.overwriteChannel(data.permission_overwrites).has("VIEW_CHANNEL")) {
if (exists) break;
listenEvent(id, consumer, listenOpts);
this.events[id] = await listenEvent(id, consumer, listenOpts);
} else {
if (!exists) return; // return -> do not send channel update events for hidden channels
opts.cancel(id);

View File

@ -43,11 +43,11 @@ export interface KafkaBroker {
export interface DefaultOptions {
gateway: {
endpointClientKeepDefault?: boolean;
endpointClient: string | null;
endpoint: string | null;
};
cdn: {
endpointClientKeepDefault?: boolean;
endpointClient: string | null;
endpoint: string | null;
};
general: {
@ -150,11 +150,11 @@ export interface DefaultOptions {
export const DefaultOptions: DefaultOptions = {
gateway: {
endpointClientKeepDefault: false,
endpointClient: null,
endpoint: null,
},
cdn: {
endpointClientKeepDefault: false,
endpointClient: null,
endpoint: null,
},
general: {

View File

@ -16,6 +16,7 @@ export async function emitEvent(payload: Omit<Event, "created_at">) {
const successful = RabbitMQ.channel?.publish(id, "", Buffer.from(`${data}`), { type: payload.event });
if (!successful) throw new Error("failed to send event");
} else {
console.log("emit event", id);
events.emit(id, payload);
}
}
@ -44,7 +45,11 @@ export async function listenEvent(event: string, callback: (event: EventOpts) =>
// @ts-ignore
return rabbitListen(opts?.channel || RabbitMQ.channel, event, callback, { acknowledge: opts?.acknowledge });
} else {
const cancel = () => events.removeListener(event, callback);
const cancel = () => {
console.log("cancel event", event);
events.removeListener(event, callback);
};
console.log("listen event", event);
events.addListener(event, (opts) => callback({ ...opts, cancel }));
return cancel;