Skip to content

Commit

Permalink
Auto-add trailing slash to server only if needed (#403)
Browse files Browse the repository at this point in the history
* Auto-add trailing slash to server only if needed

* undo package-lock.json change
  • Loading branch information
jasonharrison authored and nicolodavis committed May 19, 2019
1 parent f289379 commit efece0c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/client/transport/socketio.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ export class SocketIO {
if (server.search(/^https?:\/\//) == -1) {
server = 'http://' + this.server;
}

this.socket = io(server + '/' + this.gameName, this.socketOpts);
if (server.substr(-1) != '/') {
// add trailing slash if not already present
server = server + '/';
}
this.socket = io(server + this.gameName, this.socketOpts);
} else {
this.socket = io('/' + this.gameName, this.socketOpts);
}
Expand Down
7 changes: 7 additions & 0 deletions src/client/transport/socketio.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ describe('server option', () => {
expect(m.socket.io.engine.secure).toEqual(false);
});

test('without trailing slash', () => {
const server = 'http://' + hostname + ':' + port;
const m = new SocketIO({ server });
m.connect();
expect(m.socket.io.uri).toEqual(server + '/default');
});

test('https', () => {
const serverWithProtocol = 'https://' + hostname + ':' + port + '/';
const m = new SocketIO({ server: serverWithProtocol });
Expand Down

0 comments on commit efece0c

Please sign in to comment.