1
- 'use strict' ;
2
-
3
1
// Do this as the first thing so that any code reading it knows the right env.
4
2
process . env . BABEL_ENV = 'development' ;
5
3
process . env . NODE_ENV = 'development' ;
6
4
7
5
// Makes the script crash on unhandled rejections instead of silently
8
6
// ignoring them. In the future, promise rejections that are not handled will
9
7
// terminate the Node.js process with a non-zero exit code.
10
- process . on ( 'unhandledRejection' , err => {
8
+ process . on ( 'unhandledRejection' , ( err ) => {
11
9
throw err ;
12
10
} ) ;
13
11
14
12
// Ensure environment variables are read.
15
13
require ( '../config/env' ) ;
16
14
17
-
18
15
const fs = require ( 'fs' ) ;
19
16
const chalk = require ( 'react-dev-utils/chalk' ) ;
20
17
const webpack = require ( 'webpack' ) ;
@@ -48,15 +45,15 @@ if (process.env.HOST) {
48
45
console . log (
49
46
chalk . cyan (
50
47
`Attempting to bind to HOST environment variable: ${ chalk . yellow (
51
- chalk . bold ( process . env . HOST )
52
- ) } `
53
- )
48
+ chalk . bold ( process . env . HOST ) ,
49
+ ) } `,
50
+ ) ,
54
51
) ;
55
52
console . log (
56
- `If this was unintentional, check that you haven't mistakenly set it in your shell.`
53
+ `If this was unintentional, check that you haven't mistakenly set it in your shell.` ,
57
54
) ;
58
55
console . log (
59
- `Learn more here: ${ chalk . yellow ( 'https://bit.ly/CRA-advanced-config' ) } `
56
+ `Learn more here: ${ chalk . yellow ( 'https://bit.ly/CRA-advanced-config' ) } ` ,
60
57
) ;
61
58
console . log ( ) ;
62
59
}
@@ -70,7 +67,7 @@ checkBrowsers(paths.appPath, isInteractive)
70
67
// run on a different port. `choosePort()` Promise resolves to the next free port.
71
68
return choosePort ( HOST , DEFAULT_PORT ) ;
72
69
} )
73
- . then ( port => {
70
+ . then ( ( port ) => {
74
71
if ( port == null ) {
75
72
// We have not found a port.
76
73
return ;
@@ -82,9 +79,9 @@ checkBrowsers(paths.appPath, isInteractive)
82
79
const tscCompileOnError = process . env . TSC_COMPILE_ON_ERROR === 'true' ;
83
80
const urls = prepareUrls ( protocol , HOST , port ) ;
84
81
const devSocket = {
85
- warnings : warnings =>
82
+ warnings : ( warnings ) =>
86
83
devServer . sockWrite ( devServer . sockets , 'warnings' , warnings ) ,
87
- errors : errors =>
84
+ errors : ( errors ) =>
88
85
devServer . sockWrite ( devServer . sockets , 'errors' , errors ) ,
89
86
} ;
90
87
// Create a webpack compiler that is configured with custom messages.
@@ -99,16 +96,19 @@ checkBrowsers(paths.appPath, isInteractive)
99
96
webpack,
100
97
} ) ;
101
98
// Load proxy config
102
- const proxySetting = require ( paths . appPackageJson ) . proxy ;
99
+ const proxySetting =
100
+ process . env . NODE_ENV !== 'production'
101
+ ? process . env . REACT_APP_API_HOST
102
+ : require ( paths . appPackageJson ) . proxy ;
103
103
const proxyConfig = prepareProxy ( proxySetting , paths . appPublic ) ;
104
104
// Serve webpack assets generated by the compiler over a web server.
105
105
const serverConfig = createDevServerConfig (
106
106
proxyConfig ,
107
- urls . lanUrlForConfig
107
+ urls . lanUrlForConfig ,
108
108
) ;
109
109
const devServer = new WebpackDevServer ( compiler , serverConfig ) ;
110
110
// Launch WebpackDevServer.
111
- devServer . listen ( port , HOST , err => {
111
+ devServer . listen ( port , HOST , ( err ) => {
112
112
if ( err ) {
113
113
return console . log ( err ) ;
114
114
}
@@ -122,8 +122,8 @@ checkBrowsers(paths.appPath, isInteractive)
122
122
if ( process . env . NODE_PATH ) {
123
123
console . log (
124
124
chalk . yellow (
125
- 'Setting NODE_PATH to resolve modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using TypeScript) and will be removed in a future major release of create-react-app.'
126
- )
125
+ 'Setting NODE_PATH to resolve modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using TypeScript) and will be removed in a future major release of create-react-app.' ,
126
+ ) ,
127
127
) ;
128
128
console . log ( ) ;
129
129
}
@@ -132,14 +132,14 @@ checkBrowsers(paths.appPath, isInteractive)
132
132
openBrowser ( urls . localUrlForBrowser ) ;
133
133
} ) ;
134
134
135
- [ 'SIGINT' , 'SIGTERM' ] . forEach ( function ( sig ) {
136
- process . on ( sig , function ( ) {
135
+ [ 'SIGINT' , 'SIGTERM' ] . forEach ( function ( sig ) {
136
+ process . on ( sig , function ( ) {
137
137
devServer . close ( ) ;
138
138
process . exit ( ) ;
139
139
} ) ;
140
140
} ) ;
141
141
} )
142
- . catch ( err => {
142
+ . catch ( ( err ) => {
143
143
if ( err && err . message ) {
144
144
console . log ( err . message ) ;
145
145
}
0 commit comments