Skip to content

Commit bde6ead

Browse files
Merge branch 'master' into update-scripts
2 parents 9b3bc57 + 7169c01 commit bde6ead

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+807
-751
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ Options:
124124
--no-history-api-fallback Do not fallback to /index.html for Single Page Applications.
125125
--compress Enable gzip compression.
126126
--no-compress Disable gzip compression.
127-
--public <value> The public hostname/ip address of the server.
128127
--firewall [value...] Enable firewall or set hosts that are allowed to access the dev server.
129128
--no-firewall Disable firewall.
130129
--watch-files <value...> Watch static files for file changes.

bin/cli-flags.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -394,16 +394,6 @@ module.exports = {
394394
negatedDescription: 'Disable gzip compression.',
395395
negative: true,
396396
},
397-
{
398-
name: 'public',
399-
type: String,
400-
configs: [
401-
{
402-
type: 'string',
403-
},
404-
],
405-
description: 'The public hostname/ip address of the server.',
406-
},
407397
{
408398
name: 'firewall',
409399
type: [Boolean, String],

client-src/utils/createSocketURL.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ const url = require('url');
77
function createSocketURL(parsedURL) {
88
let { auth, hostname, protocol, port } = parsedURL;
99

10-
const getURLSearchParam = (name) => {
11-
if (parsedURL.searchParams) {
12-
return parsedURL.searchParams.get(name);
13-
}
14-
15-
return parsedURL.query && parsedURL.query[name];
16-
};
17-
1810
// Node.js module parses it as `::`
1911
// `new URL(urlString, [baseURLstring])` parses it as '[::]'
2012
const isInAddrAny =
@@ -66,22 +58,25 @@ function createSocketURL(parsedURL) {
6658
//
6759
// All of these sock url params are optionally passed in through resourceQuery,
6860
// so we need to fall back to the default if they are not provided
69-
const socketURLHostname = (
70-
getURLSearchParam('host') ||
71-
hostname ||
72-
'localhost'
73-
).replace(/^\[(.*)\]$/, '$1');
61+
const socketURLHostname = (hostname || 'localhost').replace(
62+
/^\[(.*)\]$/,
63+
'$1'
64+
);
7465

7566
if (!port || port === '0') {
7667
port = self.location.port;
7768
}
7869

79-
const socketURLPort = getURLSearchParam('port') || port;
70+
const socketURLPort = port;
8071

8172
// If path is provided it'll be passed in via the resourceQuery as a
8273
// query param so it has to be parsed out of the querystring in order for the
8374
// client to open the socket to the correct location.
84-
const socketURLPathname = getURLSearchParam('path') || '/ws';
75+
let socketURLPathname = '/ws';
76+
77+
if (parsedURL.pathname && !parsedURL.fromCurrentScript) {
78+
socketURLPathname = parsedURL.pathname;
79+
}
8580

8681
return url.format({
8782
protocol: socketURLProtocol,

client-src/utils/parseURL.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ function parseURL(resourceQuery) {
88

99
if (typeof resourceQuery === 'string' && resourceQuery !== '') {
1010
// If this bundle is inlined, use the resource query to get the correct url.
11-
// format is like `?http://0.0.0.0:8096&port=8097&host=localhost`
11+
// for backward compatibility we supports:
12+
// - ?ws://0.0.0.0:8096&3Flogging=info
13+
// - ?ws%3A%2F%2F192.168.0.5%3A8080%2F%3Flogging%3Dinfo
14+
// Also we support `http` and `https` for backward compatibility too
1215
options = url.parse(
13-
resourceQuery
14-
// strip leading `?` from query string to get a valid URL
15-
.substr(1)
16-
// replace first `&` with `?` to have a valid query string
17-
.replace('&', '?'),
16+
decodeURIComponent(
17+
resourceQuery
18+
// strip leading `?` from query string to get a valid URL
19+
.substr(1)
20+
// replace first `&` with `?` to have a valid query string
21+
.replace('&', '?')
22+
),
1823
true
1924
);
2025
} else {
@@ -36,9 +41,11 @@ function parseURL(resourceQuery) {
3641

3742
if (scriptSourceURL) {
3843
options = scriptSourceURL;
44+
options.fromCurrentScript = true;
3945
}
4046
} else {
4147
options = url.parse(self.location.href, true, true);
48+
options.fromCurrentScript = true;
4249
}
4350
}
4451

examples/cli/public-protocol/app.js

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# CLI: Public Option
1+
# CLI: Web Socket URL
22

33
```console
4-
npx webpack serve --open-target --host 0.0.0.0 --public <insert local ip>:8080
4+
npx webpack serve --open-target --host 0.0.0.0 --web-socket-url <insert-host>:8080
55
```
66

77
_NOTE: replace `<insert local ip>` with your local IP Address._
88

99
In order to make the server publicly accessible the client needs to know with
1010
what host to connect to the server. If `--host 0.0.0.0` is given, the client
11-
would try to connect to `0.0.0.0`. With the `--public` option it is possible to
11+
would try to connect to `0.0.0.0`. With the `--web-socket-url` options it is possible to
1212
override this.
1313

1414
## What Should Happen
@@ -18,4 +18,4 @@ override this.
1818
3. Open the console in your browser's devtools.
1919
4. Select the 'Network' tab.
2020
5. Select the 'WS' or 'WebSockets' sub-tab.
21-
6. Verify that the WebSocket is connecting to `<insert local ip>:8080`.
21+
6. Verify that the WebSocket is connecting to `<insert-host>:8080`.
File renamed without changes.

examples/cli/public-protocol/README.md renamed to examples/cli/web-socket-url/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# CLI: Public Option Protocol
1+
# CLI: Web Socket URL Option Protocol
22

33
```console
44
npx webpack serve
55
```
66

77
_NOTE: replace `<insert local ip>` with your local IP Address._
88

9-
You're now able to explicitly define the protocol used with the `public` option
9+
You're now able to explicitly define the protocol used with the `client.webSocketURL` option
1010
(have a look to the config provided in `webpack.config.js`).
1111

1212
## What Should Happen

examples/cli/web-socket-url/app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
3+
const target = document.querySelector('#target');
4+
5+
target.innerHTML =
6+
'Please check the ws request in devtools, it should try to connect to the protocol + server defined in the webSocketURL setting.';

0 commit comments

Comments
 (0)