Skip to content

Commit

Permalink
fix(scripts): Fix process.env variable passing
Browse files Browse the repository at this point in the history
Closes #87
  • Loading branch information
halfzebra committed Dec 25, 2016
1 parent 57d365a commit b46321d
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions scripts/start.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Load environment variables from .env file.
// Suppress warnings if this file is missing.
require('dotenv').config({silent: true});

const fs = require('fs');
const chalk = require('chalk');
const webpack = require('webpack');
Expand All @@ -9,10 +13,6 @@ const openBrowser = require('react-dev-utils/openBrowser');
const historyApiFallback = require('connect-history-api-fallback');
const httpProxyMiddleware = require('http-proxy-middleware');

// Load environment variables from .env file.
// Suppress warnings if this file is missing.
require('dotenv').config({silent: true});

if (fs.existsSync('elm-package.json') === false) {
console.log('Please, run the build script from project root directory');
process.exit(0);
Expand Down Expand Up @@ -119,21 +119,25 @@ function addMiddleware(devServer) {

// Pass the scope regex both to Express and to the middleware for proxying
// of both HTTP and WebSockets to work without false positives.
var hpm = httpProxyMiddleware(pathname => mayProxy.test(pathname), {
target: proxy,
logLevel: 'silent',
onProxyReq: function(proxyReq) {
// Browers may send Origin headers even with same-origin
// requests. To prevent CORS issues, we have to change
// the Origin to match the target URL.
if (proxyReq.getHeader('origin')) {
proxyReq.setHeader('origin', proxy);
}
var hpm = httpProxyMiddleware(
function (pathname) {
return mayProxy.test(pathname);
},
onError: onProxyError(proxy),
secure: false,
changeOrigin: true,
ws: true
{
target: proxy,
logLevel: 'silent',
onProxyReq: function (proxyReq) {
// Browers may send Origin headers even with same-origin
// requests. To prevent CORS issues, we have to change
// the Origin to match the target URL.
if (proxyReq.getHeader('origin')) {
proxyReq.setHeader('origin', proxy);
}
},
onError: onProxyError(proxy),
secure: false,
changeOrigin: true,
ws: true
});
devServer.use(mayProxy, hpm);

Expand Down

0 comments on commit b46321d

Please sign in to comment.