Skip to content

Commit fb434b5

Browse files
committed
bug #1401 Follow-up #1400 (fix URLs generation) (Kocal)
This PR was merged into the main branch. Discussion ---------- Follow-up #1400 (fix URLs generation) | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no <!-- please update CHANGELOG.md file --> | Deprecations? | no <!-- please update CHANGELOG.md file --> | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT Looks like I went a bit too fast, the URLs generated in `entrypoints.json` and `manifest.json` were always in `http://` even when using flag `--server-type https`. That's now fixed, and tests were improved to prevent regressions. Commits ------- 3e149b9 Follow-up #1400 (fix URLs generation)
2 parents 5557f89 + 3e149b9 commit fb434b5

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

lib/config-generator.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ class ConfigGenerator {
604604
headers: { 'Access-Control-Allow-Origin': '*' },
605605
compress: true,
606606
historyApiFallback: true,
607+
// disabled to let HMR handle updates without full page reloads
607608
liveReload: false,
608609
// see https://github.com/symfony/webpack-encore/issues/931#issuecomment-784483725
609610
host: this.webpackConfig.runtimeConfig.devServerHost,
@@ -613,6 +614,14 @@ class ConfigGenerator {
613614
port: this.webpackConfig.runtimeConfig.devServerPort,
614615
};
615616

617+
// Forward the --server-type CLI flag (e.g. --server-type https) so
618+
// that devServerFinalIsHttps can be determined in getWebpackConfig().
619+
// configureDevServerOptions() takes precedence if it sets "server".
620+
// Use object form { type: ... } so webpack-cli can merge --server-type on top.
621+
if (this.webpackConfig.runtimeConfig.devServerServerType) {
622+
devServerOptions.server = { type: this.webpackConfig.runtimeConfig.devServerServerType };
623+
}
624+
616625
return applyOptionsCallback(
617626
this.webpackConfig.devServerOptionsConfigurationCallback,
618627
devServerOptions

lib/config/RuntimeConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class RuntimeConfig {
1717
this.environment = process.env.NODE_ENV ? process.env.NODE_ENV : 'dev';
1818

1919
this.useDevServer = false;
20+
this.devServerServerType = null;
2021
// see config-generator - getWebpackConfig()
2122
this.devServerFinalIsHttps = null;
2223
this.devServerHost = null;

lib/config/parse-runtime.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ module.exports = function(argv, cwd) {
5050
runtimeConfig.devServerHost = argv.host ? argv.host : 'localhost';
5151
runtimeConfig.devServerPort = argv.port ? argv.port : '8080';
5252

53+
if (argv.serverType) {
54+
runtimeConfig.devServerServerType = argv.serverType;
55+
}
56+
5357
break;
5458
}
5559

test/bin/encore.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,18 @@ module.exports = Encore.getWebpackConfig();
276276
expect(stderr).to.contain('[webpack-dev-server] Loopback: http://localhost:8080/');
277277
expect(stderr).to.contain('[webpack-dev-server] Content not from webpack is served from');
278278

279+
// Verify entrypoints.json contains http:// URLs
280+
const entrypoints = JSON.parse(
281+
fs.readFileSync(path.join(testDir, 'build', 'entrypoints.json'), 'utf8')
282+
);
283+
expect(entrypoints.entrypoints.main.js[0]).to.contain('http://localhost:8080/build/');
284+
285+
// Verify manifest.json contains http:// URLs
286+
const manifest = JSON.parse(
287+
fs.readFileSync(path.join(testDir, 'build', 'manifest.json'), 'utf8')
288+
);
289+
expect(manifest['build/main.js']).to.contain('http://localhost:8080/build/');
290+
279291
done();
280292
});
281293

@@ -344,6 +356,19 @@ module.exports = Encore.getWebpackConfig();
344356
expect(stderr).to.contain('[webpack-dev-server] Loopback: https://localhost:8080/');
345357
expect(stderr).to.contain('[webpack-dev-server] Content not from webpack is served from');
346358

359+
// Verify entrypoints.json contains https:// URLs
360+
const entrypoints = JSON.parse(
361+
fs.readFileSync(path.join(testDir, 'build', 'entrypoints.json'), 'utf8')
362+
);
363+
364+
expect(entrypoints.entrypoints.main.js[0]).to.contain('https://localhost:8080/build/');
365+
366+
// Verify manifest.json contains https:// URLs
367+
const manifest = JSON.parse(
368+
fs.readFileSync(path.join(testDir, 'build', 'manifest.json'), 'utf8')
369+
);
370+
expect(manifest['build/main.js']).to.contain('https://localhost:8080/build/');
371+
347372
done();
348373
});
349374

test/config/parse-runtime.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ describe('parse-runtime', function() {
8787
const config = parseArgv(createArgv(['dev-server', '--server-type', 'https', '--host', 'foohost.l', '--port', '9999']), testDir);
8888

8989
expect(config.useDevServer).to.be.true;
90+
expect(config.devServerServerType).to.equal('https');
9091
expect(config.devServerHost).to.equal('foohost.l');
9192
expect(config.devServerPort).to.equal(9999);
9293
});

0 commit comments

Comments
 (0)