@@ -2,8 +2,8 @@ const httpProxy = require("http-proxy");
2
2
const http = require ( "http" ) ;
3
3
const fs = require ( "fs" ) ;
4
4
const program = require ( "commander" ) ;
5
- const pathCustomConfig = "./.react-scripts-ssr.json" ;
6
5
const openBrowser = require ( "react-dev-utils/openBrowser" ) ;
6
+ const pathsSSRScripts = require ( "../config/paths" ) ;
7
7
8
8
program
9
9
. version ( "0.1.0" )
@@ -31,10 +31,14 @@ program
31
31
32
32
let customHttpProxyConfig = { proxy : { } } ;
33
33
try {
34
- if ( fs . existsSync ( pathCustomConfig ) ) {
35
- customConfig = JSON . parse ( fs . readFileSync ( pathCustomConfig ) ) ;
34
+ if ( fs . existsSync ( pathsSSRScripts . customScriptConfig ) ) {
35
+ customConfig = JSON . parse (
36
+ fs . readFileSync ( pathsSSRScripts . customScriptConfig )
37
+ ) ;
36
38
if ( customConfig . proxy ) {
37
- customHttpProxyConfig = customConfig ;
39
+ customHttpProxyConfig = customConfig . proxy ;
40
+ } else {
41
+ throw new Error ( "customConfig doesn't have a key called proxy" ) ;
38
42
}
39
43
}
40
44
} catch ( error ) {
@@ -44,22 +48,18 @@ try {
44
48
}
45
49
46
50
const WEB_HOST =
47
- program . webHost || customHttpProxyConfig . proxy . webHost || "localhost" ;
48
- const WEB_PORT =
49
- program . webPort || customHttpProxyConfig . proxy . webPort || "3000" ;
51
+ program . webHost || customHttpProxyConfig . webHost || "localhost" ;
52
+ const WEB_PORT = program . webPort || customHttpProxyConfig . webPort || "3000" ;
50
53
const WEB_URL = `http://${ WEB_HOST } :${ WEB_PORT } ` ;
51
54
const API_URL =
52
- program . apiUrl ||
53
- customHttpProxyConfig . proxy . apiUrl ||
54
- "http://localhost:8080" ;
55
- const PROXY_PORT =
56
- program . proxyPort || customHttpProxyConfig . proxy . proxyPort || 5050 ;
55
+ program . apiUrl || customHttpProxyConfig . apiUrl || "http://localhost:8080" ;
56
+ const PROXY_PORT = program . proxyPort || customHttpProxyConfig . proxyPort || 5050 ;
57
57
const PROXY_HOST =
58
- program . proxyHost || customHttpProxyConfig . proxy . proxyHost || "localhost" ;
58
+ program . proxyHost || customHttpProxyConfig . proxyHost || "localhost" ;
59
59
60
60
const proxy = httpProxy . createProxyServer ( {
61
61
ws : true ,
62
- ...customHttpProxyConfig . proxy
62
+ ...customHttpProxyConfig
63
63
} ) ;
64
64
65
65
var server = http . createServer ( ( req , res ) => {
0 commit comments