Skip to content

Commit b2b41da

Browse files
skevyFacebook Github Bot 1
authored andcommitted
Don't hardcode 'localhost:8081' as the _hmrURL in the Bundler
Summary:martinbigio this fixes your TODO. 🚀 🚀 🚀 Closes facebook#5827 Differential Revision: D2932188 Pulled By: martinbigio fb-gh-sync-id: 8c8caf0782f05b51c90c8d09fdb743ddd3e6f97e shipit-source-id: 8c8caf0782f05b51c90c8d09fdb743ddd3e6f97e
1 parent 20588a6 commit b2b41da

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

local-cli/server/util/attachHMRServer.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,23 @@ function attachHMRServer({httpServer, path, packagerServer}) {
185185
return;
186186
}
187187

188+
const httpServerAddress = httpServer.address();
189+
190+
// Sanitize the value from the HTTP server
191+
let packagerHost = 'localhost';
192+
if (httpServer.address().address &&
193+
httpServer.address().address !== '::' &&
194+
httpServer.address().address !== '') {
195+
packagerHost = httpServerAddress.address;
196+
}
197+
198+
let packagerPort = httpServerAddress.port;
199+
188200
return packagerServer.buildBundleForHMR({
189201
entryFile: client.bundleEntry,
190202
platform: client.platform,
191203
resolutionResponse,
192-
});
204+
}, packagerHost, packagerPort);
193205
})
194206
.then(bundle => {
195207
if (!client || !bundle || bundle.isEmpty()) {

packager/react-packager/src/Bundler/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ class Bundler {
168168
});
169169
}
170170

171-
_sourceHMRURL(platform, path) {
171+
_sourceHMRURL(platform, host, port, path) {
172172
return this._hmrURL(
173-
'http://localhost:8081', // TODO: (martinb) avoid hardcoding
173+
`http://${host}:${port}`,
174174
platform,
175175
'bundle',
176176
path,
@@ -211,10 +211,10 @@ class Bundler {
211211
);
212212
}
213213

214-
hmrBundle(options) {
214+
hmrBundle(options, host, port) {
215215
return this._bundle({
216216
bundle: new HMRBundle({
217-
sourceURLFn: this._sourceHMRURL.bind(this, options.platform),
217+
sourceURLFn: this._sourceHMRURL.bind(this, options.platform, host, port),
218218
sourceMappingURLFn: this._sourceMappingHMRURL.bind(
219219
this,
220220
options.platform,

packager/react-packager/src/Server/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ class Server {
240240
return this.buildBundle(options);
241241
}
242242

243-
buildBundleForHMR(modules) {
244-
return this._bundler.hmrBundle(modules);
243+
buildBundleForHMR(modules, host, port) {
244+
return this._bundler.hmrBundle(modules, host, port);
245245
}
246246

247247
getShallowDependencies(entryFile) {

0 commit comments

Comments
 (0)