Skip to content

Commit efece0c

Browse files
jasonharrisonnicolodavis
authored andcommitted
Auto-add trailing slash to server only if needed (#403)
* Auto-add trailing slash to server only if needed * undo package-lock.json change
1 parent f289379 commit efece0c

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/client/transport/socketio.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ export class SocketIO {
7272
if (server.search(/^https?:\/\//) == -1) {
7373
server = 'http://' + this.server;
7474
}
75-
76-
this.socket = io(server + '/' + this.gameName, this.socketOpts);
75+
if (server.substr(-1) != '/') {
76+
// add trailing slash if not already present
77+
server = server + '/';
78+
}
79+
this.socket = io(server + this.gameName, this.socketOpts);
7780
} else {
7881
this.socket = io('/' + this.gameName, this.socketOpts);
7982
}

src/client/transport/socketio.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ describe('server option', () => {
144144
expect(m.socket.io.engine.secure).toEqual(false);
145145
});
146146

147+
test('without trailing slash', () => {
148+
const server = 'http://' + hostname + ':' + port;
149+
const m = new SocketIO({ server });
150+
m.connect();
151+
expect(m.socket.io.uri).toEqual(server + '/default');
152+
});
153+
147154
test('https', () => {
148155
const serverWithProtocol = 'https://' + hostname + ':' + port + '/';
149156
const m = new SocketIO({ server: serverWithProtocol });

0 commit comments

Comments
 (0)