@jsenv/server 12.7.5 → 12.8.0
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
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { networkInterfaces } from "node:os"
|
|
2
|
+
import { lookup } from "node:dns"
|
|
2
3
|
|
|
3
|
-
export const getServerOrigins = ({ protocol, ip, port }) => {
|
|
4
|
+
export const getServerOrigins = async ({ protocol, ip, port }) => {
|
|
4
5
|
const isInternalIp = ip === "127.0.0.1"
|
|
6
|
+
const localhostDnsResolution = await applyDnsResolution("localhost")
|
|
5
7
|
const internalOrigin = createServerOrigin({
|
|
6
8
|
protocol,
|
|
7
|
-
hostname:
|
|
9
|
+
hostname:
|
|
10
|
+
localhostDnsResolution.address === "127.0.0.1"
|
|
11
|
+
? "localhost"
|
|
12
|
+
: "127.0.0.1",
|
|
8
13
|
port,
|
|
9
14
|
})
|
|
10
15
|
if (isInternalIp) {
|
|
@@ -21,6 +26,19 @@ export const getServerOrigins = ({ protocol, ip, port }) => {
|
|
|
21
26
|
}
|
|
22
27
|
}
|
|
23
28
|
|
|
29
|
+
const applyDnsResolution = async (hostname) => {
|
|
30
|
+
const dnsResolution = await new Promise((resolve, reject) => {
|
|
31
|
+
lookup(hostname, (error, address, family) => {
|
|
32
|
+
if (error) {
|
|
33
|
+
reject(error)
|
|
34
|
+
} else {
|
|
35
|
+
resolve({ address, family })
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
return dnsResolution
|
|
40
|
+
}
|
|
41
|
+
|
|
24
42
|
const createServerOrigin = ({ protocol, hostname, port }) => {
|
|
25
43
|
const url = new URL("https://127.0.0.1:80")
|
|
26
44
|
url.protocol = protocol
|
package/src/startServer.js
CHANGED
|
@@ -208,7 +208,7 @@ export const startServer = async ({
|
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
status = "opened"
|
|
211
|
-
const serverOrigins = getServerOrigins({ protocol, ip, port })
|
|
211
|
+
const serverOrigins = await getServerOrigins({ protocol, ip, port })
|
|
212
212
|
const serverOrigin = serverOrigins.internal
|
|
213
213
|
|
|
214
214
|
const removeConnectionErrorListener = listenServerConnectionError(
|