Merge branch 'webpack-refactor-devserver-env' into 'develop'

Webpack: refactor devserver env

See merge request soapbox-pub/soapbox-fe!850
merge-requests/851/merge
Alex Gleason 3 years ago
commit 250b945d03

@ -7,9 +7,17 @@ const sharedConfig = require('./shared');
const watchOptions = {}; const watchOptions = {};
const backendUrl = process.env.BACKEND_URL || 'http://localhost:4000'; const {
const patronUrl = process.env.PATRON_URL || 'http://localhost:3037'; DEVSERVER_URL,
const secureProxy = !(process.env.PROXY_HTTPS_INSECURE === 'true'); BACKEND_URL,
PATRON_URL,
PROXY_HTTPS_INSECURE,
} = process.env;
const DEFAULTS = {
DEVSERVER_URL: 'http://localhost:3036',
PATRON_URL: 'http://localhost:3037',
};
const { FE_SUBDIRECTORY } = require(join(__dirname, '..', 'app', 'soapbox', 'build_config')); const { FE_SUBDIRECTORY } = require(join(__dirname, '..', 'app', 'soapbox', 'build_config'));
@ -28,15 +36,17 @@ const backendEndpoints = [
]; ];
const makeProxyConfig = () => { const makeProxyConfig = () => {
const secureProxy = PROXY_HTTPS_INSECURE !== 'true';
const proxyConfig = {}; const proxyConfig = {};
proxyConfig['/api/patron'] = { proxyConfig['/api/patron'] = {
target: patronUrl, target: PATRON_URL || DEFAULTS.PATRON_URL,
secure: secureProxy, secure: secureProxy,
changeOrigin: true, changeOrigin: true,
}; };
backendEndpoints.map(endpoint => { backendEndpoints.map(endpoint => {
proxyConfig[endpoint] = { proxyConfig[endpoint] = {
target: backendUrl, target: BACKEND_URL || DEFAULTS.BACKEND_URL,
secure: secureProxy, secure: secureProxy,
changeOrigin: true, changeOrigin: true,
}; };
@ -51,6 +61,14 @@ if (process.env.VAGRANT) {
watchOptions.poll = 1000; watchOptions.poll = 1000;
} }
const devServerUrl = (() => {
try {
return new URL(DEVSERVER_URL);
} catch {
return new URL(DEFAULTS.DEVSERVER_URL);
}
})();
module.exports = merge(sharedConfig, { module.exports = merge(sharedConfig, {
mode: 'development', mode: 'development',
cache: true, cache: true,
@ -73,9 +91,9 @@ module.exports = merge(sharedConfig, {
devServer: { devServer: {
compress: true, compress: true,
host: 'localhost', host: devServerUrl.hostname,
port: 3036, port: devServerUrl.port,
https: false, https: devServerUrl.protocol === 'https:',
hot: false, hot: false,
allowedHosts: 'all', allowedHosts: 'all',
historyApiFallback: { historyApiFallback: {

Loading…
Cancel
Save