Skip to content

Commit

Permalink
server context path applied correctly mockoon#83
Browse files Browse the repository at this point in the history
  • Loading branch information
isuru89 committed Feb 1, 2024
1 parent d2c8d39 commit 3e8f0ba
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/commons-server/src/libs/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,14 +510,15 @@ export class MockoonServer extends (EventEmitter as new () => TypedEmitter<Serve
private createWSRoutes(wsRoutes: Route[]) {
wsRoutes.forEach((wsRoute) => {
const webSocketServer = new WebSocket.Server({
noServer: true,
path: this.environment.endpointPrefix
? `/${this.environment.endpointPrefix}/${wsRoute.endpoint}`
: undefined
noServer: true
});

this.webSocketServers.push(webSocketServer);

const envPath = this.environment.endpointPrefix
? `/${this.environment.endpointPrefix}`
: '';

webSocketServer.on(
'connection',
this.createWebSocketConnectionHandler(webSocketServer, wsRoute)
Expand All @@ -526,7 +527,7 @@ export class MockoonServer extends (EventEmitter as new () => TypedEmitter<Serve
this.serverInstance.on('upgrade', (req, socket, head) => {
//
const urlParsed = parseUrl(req.url || '', true);
if (urlParsed.pathname === `/${wsRoute.endpoint}`) {
if (urlParsed.pathname === `${envPath}/${wsRoute.endpoint}`) {
webSocketServer.handleUpgrade(req, socket, head, (client) => {
webSocketServer.emit('connection', client, req);
});
Expand Down

0 comments on commit 3e8f0ba

Please sign in to comment.