Skip to content

Commit b46321d

Browse files
committed
fix(scripts): Fix process.env variable passing
Closes #87
1 parent 57d365a commit b46321d

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

scripts/start.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Load environment variables from .env file.
2+
// Suppress warnings if this file is missing.
3+
require('dotenv').config({silent: true});
4+
15
const fs = require('fs');
26
const chalk = require('chalk');
37
const webpack = require('webpack');
@@ -9,10 +13,6 @@ const openBrowser = require('react-dev-utils/openBrowser');
913
const historyApiFallback = require('connect-history-api-fallback');
1014
const httpProxyMiddleware = require('http-proxy-middleware');
1115

12-
// Load environment variables from .env file.
13-
// Suppress warnings if this file is missing.
14-
require('dotenv').config({silent: true});
15-
1616
if (fs.existsSync('elm-package.json') === false) {
1717
console.log('Please, run the build script from project root directory');
1818
process.exit(0);
@@ -119,21 +119,25 @@ function addMiddleware(devServer) {
119119

120120
// Pass the scope regex both to Express and to the middleware for proxying
121121
// of both HTTP and WebSockets to work without false positives.
122-
var hpm = httpProxyMiddleware(pathname => mayProxy.test(pathname), {
123-
target: proxy,
124-
logLevel: 'silent',
125-
onProxyReq: function(proxyReq) {
126-
// Browers may send Origin headers even with same-origin
127-
// requests. To prevent CORS issues, we have to change
128-
// the Origin to match the target URL.
129-
if (proxyReq.getHeader('origin')) {
130-
proxyReq.setHeader('origin', proxy);
131-
}
122+
var hpm = httpProxyMiddleware(
123+
function (pathname) {
124+
return mayProxy.test(pathname);
132125
},
133-
onError: onProxyError(proxy),
134-
secure: false,
135-
changeOrigin: true,
136-
ws: true
126+
{
127+
target: proxy,
128+
logLevel: 'silent',
129+
onProxyReq: function (proxyReq) {
130+
// Browers may send Origin headers even with same-origin
131+
// requests. To prevent CORS issues, we have to change
132+
// the Origin to match the target URL.
133+
if (proxyReq.getHeader('origin')) {
134+
proxyReq.setHeader('origin', proxy);
135+
}
136+
},
137+
onError: onProxyError(proxy),
138+
secure: false,
139+
changeOrigin: true,
140+
ws: true
137141
});
138142
devServer.use(mayProxy, hpm);
139143

0 commit comments

Comments
 (0)