Commit 89f9a373 authored by Stan Hu's avatar Stan Hu

Support configuring HTTPS with Webpack dev server

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/80196 appears to
have broken development users who have configured their GDKs to use
HTTPS. Unless Webpack's `devServer.webSocketServer` is set to `false`,
a Websocket connection attempts to connect to an HTTP
endpoint. However, for security reasons browsers block mixed content
(https://support.mozilla.org/en-US/kb/mixed-content-blocking-firefox).

To fix this, we make it possible to enable and configure HTTPS via the
following environment variables:

* DEV_SERVER_TYPE
* DEV_SERVER_SSL_KEY
* DEV_SERVER_SSL_CERT

Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/352648
parent 24775542
...@@ -40,11 +40,16 @@ const CACHE_PATH = process.env.WEBPACK_CACHE_PATH || path.join(ROOT_PATH, 'tmp/c ...@@ -40,11 +40,16 @@ const CACHE_PATH = process.env.WEBPACK_CACHE_PATH || path.join(ROOT_PATH, 'tmp/c
const IS_PRODUCTION = process.env.NODE_ENV === 'production'; const IS_PRODUCTION = process.env.NODE_ENV === 'production';
const IS_DEV_SERVER = process.env.WEBPACK_SERVE === 'true'; const IS_DEV_SERVER = process.env.WEBPACK_SERVE === 'true';
const { DEV_SERVER_HOST, DEV_SERVER_PUBLIC_ADDR } = process.env; const {
DEV_SERVER_HOST,
DEV_SERVER_PUBLIC_ADDR,
DEV_SERVER_TYPE,
DEV_SERVER_SSL_KEY,
DEV_SERVER_SSL_CERT,
} = process.env;
const DEV_SERVER_PORT = parseInt(process.env.DEV_SERVER_PORT, 10); const DEV_SERVER_PORT = parseInt(process.env.DEV_SERVER_PORT, 10);
const DEV_SERVER_ALLOWED_HOSTS = const DEV_SERVER_ALLOWED_HOSTS =
process.env.DEV_SERVER_ALLOWED_HOSTS && process.env.DEV_SERVER_ALLOWED_HOSTS.split(','); process.env.DEV_SERVER_ALLOWED_HOSTS && process.env.DEV_SERVER_ALLOWED_HOSTS.split(',');
const DEV_SERVER_HTTPS = process.env.DEV_SERVER_HTTPS && process.env.DEV_SERVER_HTTPS !== 'false';
const DEV_SERVER_LIVERELOAD = IS_DEV_SERVER && process.env.DEV_SERVER_LIVERELOAD !== 'false'; const DEV_SERVER_LIVERELOAD = IS_DEV_SERVER && process.env.DEV_SERVER_LIVERELOAD !== 'false';
const INCREMENTAL_COMPILER_ENABLED = const INCREMENTAL_COMPILER_ENABLED =
IS_DEV_SERVER && IS_DEV_SERVER &&
...@@ -709,7 +714,6 @@ module.exports = { ...@@ -709,7 +714,6 @@ module.exports = {
}, },
host: DEV_SERVER_HOST || 'localhost', host: DEV_SERVER_HOST || 'localhost',
port: DEV_SERVER_PORT || 3808, port: DEV_SERVER_PORT || 3808,
https: DEV_SERVER_HTTPS,
hot: DEV_SERVER_LIVERELOAD, hot: DEV_SERVER_LIVERELOAD,
// The following settings are mainly needed for HMR support in gitpod. // The following settings are mainly needed for HMR support in gitpod.
// Per default only local hosts are allowed, but here we could // Per default only local hosts are allowed, but here we could
...@@ -720,6 +724,13 @@ module.exports = { ...@@ -720,6 +724,13 @@ module.exports = {
client: { client: {
...(DEV_SERVER_PUBLIC_ADDR ? { webSocketURL: DEV_SERVER_PUBLIC_ADDR } : {}), ...(DEV_SERVER_PUBLIC_ADDR ? { webSocketURL: DEV_SERVER_PUBLIC_ADDR } : {}),
}, },
server: {
type: DEV_SERVER_TYPE || 'http',
options: {
key: DEV_SERVER_SSL_KEY,
cert: DEV_SERVER_SSL_CERT,
},
},
}, },
devtool: NO_SOURCEMAPS ? false : devtool, devtool: NO_SOURCEMAPS ? false : devtool,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment