fix ExpressPeerServer when mount on custom path

This commit is contained in:
afrokick 2020-03-23 19:51:18 +03:00
parent e22e6acce4
commit b3f223c51f
4 changed files with 12 additions and 18 deletions

7
dist/src/index.js vendored
View File

@ -27,14 +27,7 @@ exports.ExpressPeerServer = ExpressPeerServer;
function PeerServer(options = {}, callback) {
const app = express_1.default();
const newOptions = Object.assign(Object.assign({}, config_1.default), options);
let path = newOptions.path;
const port = newOptions.port;
if (!path.startsWith('/')) {
path = "/" + path;
}
if (!path.endsWith('/')) {
path += "/";
}
let server;
if (newOptions.ssl && newOptions.ssl.key && newOptions.ssl.cert) {
server = https_1.default.createServer(options.ssl, app);

View File

@ -1,5 +1,9 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const realm_1 = require("./models/realm");
const checkBrokenConnections_1 = require("./services/checkBrokenConnections");
const messagesExpire_1 = require("./services/messagesExpire");
@ -20,10 +24,12 @@ exports.createInstance = ({ app, server, options }) => {
}
});
app.use(options.path, api);
//use mountpath for WS server
const customConfig = Object.assign(Object.assign({}, config), { path: path_1.default.join(app.path(), options.path, '/') });
const wss = new webSocketServer_1.WebSocketServer({
server,
realm,
config
config: customConfig
});
wss.on("connection", (client) => {
const messageQueue = realm.getMessageQueueById(client.getId());

View File

@ -42,17 +42,8 @@ function PeerServer(options: Optional<IConfig> = {}, callback?: (server: Server)
...options
};
let path = newOptions.path;
const port = newOptions.port;
if (!path.startsWith('/')) {
path = "/" + path;
}
if (!path.endsWith('/')) {
path += "/";
}
let server: Server;
if (newOptions.ssl && newOptions.ssl.key && newOptions.ssl.cert) {

View File

@ -1,5 +1,6 @@
import express from "express";
import { Server } from "net";
import path from 'path';
import { IClient } from "./models/client";
import { IMessage } from "./models/message";
import { Realm } from "./models/realm";
@ -32,10 +33,13 @@ export const createInstance = ({ app, server, options }: {
app.use(options.path, api);
//use mountpath for WS server
const customConfig = { ...config, path: path.join(app.path(), options.path, '/') };
const wss: IWebSocketServer = new WebSocketServer({
server,
realm,
config
config: customConfig
});
wss.on("connection", (client: IClient) => {