Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support custom url protocol scheme on websockets #1173

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions packages/kyt-core/src/config/webpackHotDevClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,31 @@ if (module.hot && typeof module.hot.dispose === 'function') {
});
}

// Connect to WebpackDevServer via a socket.
const connection = new SockJS(
url.format({
protocol: window.location.protocol,
hostname: window.location.hostname,
port: sockJSPort,
// Hardcoded in WebpackDevServer
pathname: '/sockjs-node',
})
);
let connection;
if (!window.location.protocol.includes('http')) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this protocol be https?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're https then the .includes will also match with https

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const protocol = 'https:'
protocol.includes('http') --> true

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's right 👍

Copy link

@kmnaid kmnaid Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For security, should we just have includes http OR https instead of keeping it open to any value with http?

// if the location protocol doesn't include http use a normal web-socket
// sockjs doesn't support custom protocols
connection = new WebSocket(
url.format({
protocol: 'wss',
hostname: window.location.hostname,
port: sockJSPort,
// Hardcoded in WebpackDevServer
pathname: '/sockjs-node',
})
);
} else {
// Connect to WebpackDevServer via a socket.
connection = new SockJS(
url.format({
protocol: window.location.protocol,
hostname: window.location.hostname,
port: sockJSPort,
// Hardcoded in WebpackDevServer
pathname: '/sockjs-node',
})
);
}

// Unlike WebpackDevServer client, we won't try to reconnect
// to avoid spamming the console. Disconnect usually happens
Expand Down
Loading