1+ // Load environment variables from .env file.
2+ // Suppress warnings if this file is missing.
3+ require ( 'dotenv' ) . config ( { silent : true } ) ;
4+
15const fs = require ( 'fs' ) ;
26const chalk = require ( 'chalk' ) ;
37const webpack = require ( 'webpack' ) ;
@@ -9,10 +13,6 @@ const openBrowser = require('react-dev-utils/openBrowser');
913const historyApiFallback = require ( 'connect-history-api-fallback' ) ;
1014const 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-
1616if ( 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