From 8ab1ab4c31f71280ced9ee33bd66d55d6d66db7e Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Sat, 15 May 2021 11:34:23 -0400 Subject: [PATCH 1/2] fix: PORT variable undefined --- serve/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serve/src/index.js b/serve/src/index.js index 9251e82..b4427ee 100755 --- a/serve/src/index.js +++ b/serve/src/index.js @@ -113,7 +113,7 @@ config.plugins.push(new HtmlWebpackPlugin({ // enable hot reloading if (process.env.NO_RELOAD !== "true") { config.entry.app.unshift(path.resolve(__dirname, '..', 'node_modules', 'webpack-dev-server/client/index.js') - + `?${protocol}://${useLocalhost ? 'localhost' : address}:${PORT}`) + + `?${protocol}://${useLocalhost ? 'localhost' : address}:${process.env.PORT || DEFAULT_PORT}`) config.devServer = { inline: "true" } } From 3f231fe72f63e69e58fb226f8aee892c6ac09029 Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Thu, 17 Jun 2021 17:02:58 -0400 Subject: [PATCH 2/2] Better check for port enviroment variable --- serve/src/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/serve/src/index.js b/serve/src/index.js index b4427ee..5c9e6fe 100755 --- a/serve/src/index.js +++ b/serve/src/index.js @@ -34,6 +34,7 @@ const DEFAULT_PORT = 8080 const HOST = process.env.HOST || '0.0.0.0' const protocol = 'https' const useLocalhost = process.env.USE_LOCALHOST === 'true' +const SELECT_PORT = process.env.PORT || DEFAULT_PORT; /////////////////////////////////////////////////////////////////////////////// let https = true @@ -113,7 +114,7 @@ config.plugins.push(new HtmlWebpackPlugin({ // enable hot reloading if (process.env.NO_RELOAD !== "true") { config.entry.app.unshift(path.resolve(__dirname, '..', 'node_modules', 'webpack-dev-server/client/index.js') - + `?${protocol}://${useLocalhost ? 'localhost' : address}:${process.env.PORT || DEFAULT_PORT}`) + + `?${protocol}://${useLocalhost ? 'localhost' : address}:${SELECT_PORT}`) config.devServer = { inline: "true" } } @@ -136,7 +137,7 @@ compiler.plugin('done', stats => { }) // end compiler.plugin on done // Find available port and launch WebpackDevServer -nextAvailable(process.env.PORT || DEFAULT_PORT).then((PORT) => { +nextAvailable(SELECT_PORT).then((PORT) => { // Exit if user defined port is in use if (process.env.PORT && (process.env.PORT != PORT)) { console.log('ERROR: Port ' + process.env.PORT + ' is in use by another process.')