Skip to content

Commit c747018

Browse files
pappasamshellscape
andauthored
feat: add client.protocol override option for client (#218)
* Add `client.protocol` override option for client Enables users of reverse proxies to specify a different protocol scheme for client requests (typically `wss` from the browser) from the protocol scheme served by the server (typically `ws`). * Add properly-typed protocol to validation * Update tests for client * change `serverProtocol` back to `protocol` Co-authored-by: Andrew Powell <[email protected]> Co-authored-by: Andrew Powell <[email protected]>
1 parent 4e29442 commit c747018

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ Type: `String`
103103

104104
If set, allows for overriding the `WebSocket` address, which corresponds to the server address by default. Values for this option should be in a valid `{host}:{port}` format. e.g. `localhost:433`.
105105

106+
#### `client.protocol`
107+
Type: `String`
108+
109+
If set, allows for overriding the `WebSocket` protocol scheme string, which corresponds to the server protocol scheme by default. Values for this option should be one of the following: `ws` or `wss`.
110+
106111
#### `client.retry`
107112
Type: `Boolean`
108113

lib/client/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const run = (buildHash, options) => {
2424
const { error, info, warn } = require('./log')();
2525

2626
const protocol = secure ? 'wss' : 'ws';
27-
const socket = new ClientSocket(client, `${protocol}://${client.address || address}/wps`);
27+
const socket = new ClientSocket(client, `${client.protocol || protocol}://${client.address || address}/wps`);
2828

2929
const { compilerName } = options;
3030

lib/validate.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module.exports = {
3535
allowMany: boolean(),
3636
client: partial({
3737
address: string(),
38+
protocol: union([literal('ws'), literal('wss')]),
3839
retry: boolean(),
3940
silent: boolean()
4041
}),

test/validate.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ test('defaults', (t) => {
1010
});
1111

1212
test('client', (t) => {
13-
const result = validate({ client: { address: '0', retry: false, silent: false } });
13+
const result = validate({ client: { address: '0', protocol: "wss", retry: false, silent: false } });
1414
t.falsy(result.error);
15+
16+
const resultWs = validate({ client: { address: '0', protocol: "ws", retry: false, silent: false } });
17+
t.falsy(resultWs.error);
18+
19+
const resultProtocolBad = validate({ client: { address: '0', protocol: "lala", retry: false, silent: false } });
20+
t.truthy(resultProtocolBad.error);
1521
});
1622

1723
test('error', (t) => {

0 commit comments

Comments
 (0)