Skip to content

Commit 2356894

Browse files
authored
fix: Socket url compose in entry file (#565)
1 parent 10c9ef3 commit 2356894

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

server/middleware/store.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = async (ctx, next) => {
2121
if (!serverUrl.startsWith('http')) {
2222
serverUrl = `http://${serverUrl}`;
2323
}
24-
if (!socketUrl.startsWith('ws://')) {
24+
if (!socketUrl.startsWith('ws')) {
2525
socketUrl = `ws://${socketUrl}`;
2626
}
2727

src/utils/sock-client.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ let reopenCount = 0;
1414

1515
class SockClient extends EventEmitter {
1616
static composeEndpoint = (socketUrl, accessToken = '') => {
17-
const re = /(\w+?:\/\/)?([^\\?]+)/;
17+
const re = /wss?:\/\/([^\\?]+)/;
1818
const suffix = `?sid=${accessToken}`;
1919
const matchParts = `${socketUrl}`.match(re);
20-
let wsPrefix = 'ws://';
21-
if (typeof window === 'object' && window.location.protocol === 'https:') {
22-
wsPrefix = 'wss://';
20+
21+
if (!matchParts) {
22+
throw Error(`Invalid socket url: ${socketUrl}`);
2323
}
2424

25-
return `${wsPrefix}${matchParts[2]}${suffix}`;
25+
return `${matchParts[0]}${suffix}`;
2626
};
2727

2828
constructor(endpoint, options = {}) {

0 commit comments

Comments
 (0)