@jsenv/server 12.7.3 → 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,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/server",
3
- "version": "12.7.3",
3
+ "version": "12.8.0",
4
4
  "description": "Write your Node.js server using pure functions",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -17,8 +17,7 @@
17
17
  "node": ">=16.13.0"
18
18
  },
19
19
  "publishConfig": {
20
- "access": "public",
21
- "registry": "https://registry.npmjs.org"
20
+ "access": "public"
22
21
  },
23
22
  "type": "module",
24
23
  "exports": {
@@ -36,7 +35,7 @@
36
35
  },
37
36
  "dependencies": {
38
37
  "@jsenv/abort": "4.2.3",
39
- "@jsenv/log": "2.1.0",
38
+ "@jsenv/log": "3.1.0",
40
39
  "@jsenv/url-meta": "7.0.0",
41
40
  "@jsenv/utils": "2.0.1"
42
41
  },
@@ -44,4 +43,4 @@
44
43
  "@jsenv/fetch": "../fetch/",
45
44
  "eventsource": "2.0.2"
46
45
  }
47
- }
46
+ }
@@ -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: "localhost",
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
@@ -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(