@abcnews/aunty 13.0.0 → 13.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/config/serve.js +43 -31
package/package.json
CHANGED
package/src/config/serve.js
CHANGED
|
@@ -23,32 +23,7 @@ const DEFAULT_HOST = (module.exports.DEFAULT_HOST = probe(`nucwed${INTERNAL_SUFF
|
|
|
23
23
|
: 'localhost');
|
|
24
24
|
const DEFAULT_PORT = 8000;
|
|
25
25
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
module.exports.getServeConfig = () => serveConfigPromise;
|
|
29
|
-
|
|
30
|
-
async function getServeConfigPromise() {
|
|
31
|
-
const { serve } = getProjectConfig();
|
|
32
|
-
|
|
33
|
-
const config = combine(
|
|
34
|
-
{
|
|
35
|
-
hasBundleAnalysis: false,
|
|
36
|
-
host: DEFAULT_HOST,
|
|
37
|
-
hot: process.env.NODE_ENV === 'development',
|
|
38
|
-
https: true,
|
|
39
|
-
port: DEFAULT_PORT
|
|
40
|
-
},
|
|
41
|
-
serve,
|
|
42
|
-
addEnvironmentVariables,
|
|
43
|
-
addUserSSLConfig
|
|
44
|
-
);
|
|
45
|
-
const port = await findPort(config.port, config.port + 100, config.host);
|
|
46
|
-
config.port = port;
|
|
47
|
-
|
|
48
|
-
return config;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function addEnvironmentVariables(config) {
|
|
26
|
+
const addEnvironmentVariables = config => {
|
|
52
27
|
if (process.env.AUNTY_HOST) {
|
|
53
28
|
config.host = process.env.AUNTY_HOST;
|
|
54
29
|
}
|
|
@@ -58,7 +33,7 @@ function addEnvironmentVariables(config) {
|
|
|
58
33
|
}
|
|
59
34
|
|
|
60
35
|
return config;
|
|
61
|
-
}
|
|
36
|
+
};
|
|
62
37
|
|
|
63
38
|
const getSSLPath = (module.exports.getSSLPath = (host, name) => join(HOME_DIR, SSL_DIR, host, name || '.'));
|
|
64
39
|
|
|
@@ -66,7 +41,7 @@ const getSSLPath = (module.exports.getSSLPath = (host, name) => join(HOME_DIR, S
|
|
|
66
41
|
Set config.https to cert & key generated with `aunty sign-cert` (if they both exist)
|
|
67
42
|
We expect them to be in: ~/.aunty/ssl/<host>/server.{cert|key}
|
|
68
43
|
*/
|
|
69
|
-
|
|
44
|
+
const addUserSSLConfig = config => {
|
|
70
45
|
if (config.https === true) {
|
|
71
46
|
try {
|
|
72
47
|
config.https = {
|
|
@@ -77,9 +52,9 @@ function addUserSSLConfig(config) {
|
|
|
77
52
|
}
|
|
78
53
|
|
|
79
54
|
return config;
|
|
80
|
-
}
|
|
55
|
+
};
|
|
81
56
|
|
|
82
|
-
async
|
|
57
|
+
const findPort = async (port, max = port + 100, host = '0.0.0.0') => {
|
|
83
58
|
return new Promise((resolve, reject) => {
|
|
84
59
|
const socket = new Socket();
|
|
85
60
|
|
|
@@ -115,4 +90,41 @@ async function findPort(port, max = port + 100, host = '0.0.0.0') {
|
|
|
115
90
|
|
|
116
91
|
socket.connect(port, host);
|
|
117
92
|
});
|
|
118
|
-
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const _getServeConfig = async () => {
|
|
96
|
+
const { serve } = getProjectConfig();
|
|
97
|
+
|
|
98
|
+
const config = combine(
|
|
99
|
+
{
|
|
100
|
+
hasBundleAnalysis: false,
|
|
101
|
+
host: DEFAULT_HOST,
|
|
102
|
+
hot: process.env.NODE_ENV === 'development',
|
|
103
|
+
https: true,
|
|
104
|
+
port: DEFAULT_PORT
|
|
105
|
+
},
|
|
106
|
+
serve,
|
|
107
|
+
addEnvironmentVariables,
|
|
108
|
+
addUserSSLConfig
|
|
109
|
+
);
|
|
110
|
+
const port = await findPort(config.port, config.port + 100, config.host);
|
|
111
|
+
config.port = port;
|
|
112
|
+
|
|
113
|
+
return config;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
let _serveConfigPromiseSingleton;
|
|
117
|
+
|
|
118
|
+
// getServeConfig is called twice during server startup, because the `serve`
|
|
119
|
+
// command calls it directly, then indirectly, via getWebpackDevServerConfig.
|
|
120
|
+
// Because it won't change during a single `serve` command, and because we
|
|
121
|
+
// don't want to waste time doing port lookups with `findPort` multiple times
|
|
122
|
+
// we just cache the promise created on the first run, and return that later.
|
|
123
|
+
|
|
124
|
+
module.exports.getServeConfig = async () => {
|
|
125
|
+
if (!_serveConfigPromiseSingleton) {
|
|
126
|
+
_serveConfigPromiseSingleton = _getServeConfig();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return _serveConfigPromiseSingleton;
|
|
130
|
+
};
|