-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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(client): Make public path on client match dev server publicPath #2055
Closed
Closed
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
06f6c53
chore: don't support Node6 (#1976)
hiroppy af76891
refactor(client): make use of ESM instead of CJS (#1967)
hiroppy fad833a
chore(deps): update dependency ws to v7 (#1834)
renovate[bot] b32f7a3
chore(deps): update dependency file-loader to v4 (#1971)
renovate[bot] 342fa6a
chore(deps): update dependency chokidar to v3 (#1902)
renovate[bot] 7901428
chore(deps): introduce open and remove opn (#1865)
hiroppy 898461a
chore: fix tests (#1997)
hiroppy 7526664
test: make use of async/await (#1996)
hiroppy ec86384
feat(client): delete `none` and `warning` from clientLogLevel (#1998)
hiroppy 742aa13
chore: fix code from master
hiroppy b136055
chore(deps): update dependency p-retry to v4 (#2009)
hiroppy 50b99b6
fix(options): delete none and warning from optinos.json
hiroppy 5c0dced
chore(deps): update url-loader to 2.1.0
hiroppy 1679797
test: update syntax
hiroppy c600b0e
refactor(server): remove some variables of options (#2175)
hiroppy 27b1913
chore(deps): update del, supports-color, import-local and execa (#2178)
hiroppy e819cfe
feat(server): add stdin option to API (#2186)
knagaitsev 64036a0
refactor(server): move socket handling into server.listen (#2061)
knagaitsev 0e875f8
feat(server): async user callback for server.listen (#2218)
knagaitsev fe80fa4
Union sock options (#2047)
EslamHiko 54a7c77
test(client): added and improved tests for public path updating
knagaitsev ed5ee20
test(client): updated cli and index tests
knagaitsev df594ad
refactor(client): updated to latest module importing
knagaitsev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"parserOptions": { | ||
"sourceType": "module" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
'use strict'; | ||
|
||
/* eslint-disable | ||
no-unused-vars | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
'use strict'; | ||
|
||
/* eslint-disable | ||
no-unused-vars | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
'use strict'; | ||
|
||
/* global WebSocket */ | ||
|
||
/* eslint-disable | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,19 @@ | ||
'use strict'; | ||
|
||
/* global self */ | ||
|
||
const url = require('url'); | ||
const querystring = require('querystring'); | ||
const getCurrentScriptSource = require('./getCurrentScriptSource'); | ||
import url from 'url'; | ||
import getUrlParts from './getUrlParts'; | ||
|
||
function createSocketUrl(resourceQuery) { | ||
let urlParts; | ||
|
||
if (typeof resourceQuery === 'string' && resourceQuery !== '') { | ||
// If this bundle is inlined, use the resource query to get the correct url. | ||
urlParts = url.parse(resourceQuery.substr(1)); | ||
} else { | ||
// Else, get the url from the <script> this file was called with. | ||
let scriptHost = getCurrentScriptSource(); | ||
|
||
// eslint-disable-next-line no-useless-escape | ||
scriptHost = scriptHost.replace(/\/[^\/]+$/, ''); | ||
urlParts = url.parse(scriptHost || '/', false, true); | ||
} | ||
|
||
if (!urlParts.port || urlParts.port === '0') { | ||
urlParts.port = self.location.port; | ||
} | ||
|
||
const { auth, path } = urlParts; | ||
let { hostname, protocol } = urlParts; | ||
|
||
// check ipv4 and ipv6 `all hostname` | ||
// why do we need this check? | ||
// hostname n/a for file protocol (example, when using electron, ionic) | ||
// see: https://github.com/webpack/webpack-dev-server/pull/384 | ||
const isAnyHostname = | ||
(hostname === '0.0.0.0' || hostname === '::') && | ||
self.location.hostname && | ||
// eslint-disable-next-line no-bitwise | ||
!!~self.location.protocol.indexOf('http'); | ||
|
||
if (isAnyHostname) { | ||
hostname = self.location.hostname; | ||
} | ||
|
||
// `hostname` can be empty when the script path is relative. In that case, specifying | ||
// a protocol would result in an invalid URL. | ||
// When https is used in the app, secure websockets are always necessary | ||
// because the browser doesn't accept non-secure websockets. | ||
if ( | ||
hostname && | ||
(self.location.protocol === 'https:' || urlParts.hostname === '0.0.0.0') | ||
) { | ||
protocol = self.location.protocol; | ||
} | ||
|
||
// default values of the sock url if they are not provided | ||
let sockHost = hostname; | ||
let sockPath = '/sockjs-node'; | ||
let sockPort = urlParts.port; | ||
|
||
// eslint-disable-next-line no-undefined | ||
const shouldParsePath = path !== null && path !== undefined && path !== '/'; | ||
if (shouldParsePath) { | ||
const parsedQuery = querystring.parse(path); | ||
// all of these sock url params are optionally passed in through | ||
// resourceQuery, so we need to fall back to the default if | ||
// they are not provided | ||
sockHost = parsedQuery.sockHost || sockHost; | ||
sockPath = parsedQuery.sockPath || sockPath; | ||
sockPort = parsedQuery.sockPort || sockPort; | ||
} | ||
const urlParts = getUrlParts(resourceQuery); | ||
|
||
return url.format({ | ||
protocol, | ||
auth, | ||
hostname: sockHost, | ||
port: sockPort, | ||
protocol: urlParts.protocol, | ||
auth: urlParts.auth, | ||
hostname: urlParts.sockHost, | ||
port: urlParts.sockPort, | ||
// If sockPath is provided it'll be passed in via the resourceQuery as a | ||
// query param so it has to be parsed out of the querystring in order for the | ||
// client to open the socket to the correct location. | ||
pathname: sockPath, | ||
pathname: urlParts.sockPath, | ||
}); | ||
} | ||
|
||
module.exports = createSocketUrl; | ||
export default createSocketUrl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am afraid what we change global variable and it is can break code in some rare case, maybe we can rewrite this on using own variable like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean the changing of the global variable
__webpack_public_path__
, right?Good point, but the problem is that
hot-update.json
is being requested using the global public path variable here: https://github.com/webpack/webpack/blob/master/lib/web/JsonpMainTemplate.runtime.js#L31, so that global public path variable needs to be changed, or else we need to modify core webpack.I think it is safe enough to do this:
so if it is already set, we will not change it.