Skip to content

Commit

Permalink
fix: Socket url compose in entry file (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnywx authored Dec 4, 2018
1 parent 10c9ef3 commit 2356894
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion server/middleware/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = async (ctx, next) => {
if (!serverUrl.startsWith('http')) {
serverUrl = `http://${serverUrl}`;
}
if (!socketUrl.startsWith('ws://')) {
if (!socketUrl.startsWith('ws')) {
socketUrl = `ws://${socketUrl}`;
}

Expand Down
10 changes: 5 additions & 5 deletions src/utils/sock-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ let reopenCount = 0;

class SockClient extends EventEmitter {
static composeEndpoint = (socketUrl, accessToken = '') => {
const re = /(\w+?:\/\/)?([^\\?]+)/;
const re = /wss?:\/\/([^\\?]+)/;
const suffix = `?sid=${accessToken}`;
const matchParts = `${socketUrl}`.match(re);
let wsPrefix = 'ws://';
if (typeof window === 'object' && window.location.protocol === 'https:') {
wsPrefix = 'wss://';

if (!matchParts) {
throw Error(`Invalid socket url: ${socketUrl}`);
}

return `${wsPrefix}${matchParts[2]}${suffix}`;
return `${matchParts[0]}${suffix}`;
};

constructor(endpoint, options = {}) {
Expand Down

0 comments on commit 2356894

Please sign in to comment.