diff --git a/dist/src/index.js b/dist/src/index.js index 6754c83..7be958b 100644 --- a/dist/src/index.js +++ b/dist/src/index.js @@ -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); diff --git a/dist/src/instance.js b/dist/src/instance.js index 458e01c..acb0af8 100644 --- a/dist/src/instance.js +++ b/dist/src/instance.js @@ -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()); diff --git a/src/index.ts b/src/index.ts index 61f55b3..a718828 100644 --- a/src/index.ts +++ b/src/index.ts @@ -42,17 +42,8 @@ function PeerServer(options: Optional = {}, 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) { diff --git a/src/instance.ts b/src/instance.ts index cd8cc66..798c339 100644 --- a/src/instance.ts +++ b/src/instance.ts @@ -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) => {