@jsenv/core 27.3.0 → 27.3.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.
Files changed (2) hide show
  1. package/dist/main.js +21 -3
  2. package/package.json +2 -2
package/dist/main.js CHANGED
@@ -9,6 +9,7 @@ import net, { createServer } from "node:net";
9
9
  import { Readable, Stream, Writable } from "node:stream";
10
10
  import { Http2ServerResponse } from "node:http2";
11
11
  import { createReadStream, readdirSync, statSync, readFile as readFile$1, chmod, stat, lstat, readdir, promises, unlink, openSync, closeSync, rmdir, readFileSync as readFileSync$1, watch, writeFile as writeFile$1, writeFileSync as writeFileSync$1, mkdirSync, existsSync, realpathSync } from "node:fs";
12
+ import { lookup } from "node:dns";
12
13
  import { performance } from "node:perf_hooks";
13
14
  import { extname, dirname, basename } from "node:path";
14
15
  import { pathToFileURL, fileURLToPath } from "node:url";
@@ -2653,15 +2654,16 @@ const statusIsClientError = status => status >= 400 && status < 500;
2653
2654
 
2654
2655
  const statusIsServerError = status => status >= 500 && status < 600;
2655
2656
 
2656
- const getServerOrigins = ({
2657
+ const getServerOrigins = async ({
2657
2658
  protocol,
2658
2659
  ip,
2659
2660
  port
2660
2661
  }) => {
2661
2662
  const isInternalIp = ip === "127.0.0.1";
2663
+ const localhostDnsResolution = await applyDnsResolution("localhost");
2662
2664
  const internalOrigin = createServerOrigin({
2663
2665
  protocol,
2664
- hostname: "localhost",
2666
+ hostname: localhostDnsResolution.address === "127.0.0.1" ? "localhost" : "127.0.0.1",
2665
2667
  port
2666
2668
  });
2667
2669
 
@@ -2682,6 +2684,22 @@ const getServerOrigins = ({
2682
2684
  };
2683
2685
  };
2684
2686
 
2687
+ const applyDnsResolution = async hostname => {
2688
+ const dnsResolution = await new Promise((resolve, reject) => {
2689
+ lookup(hostname, (error, address, family) => {
2690
+ if (error) {
2691
+ reject(error);
2692
+ } else {
2693
+ resolve({
2694
+ address,
2695
+ family
2696
+ });
2697
+ }
2698
+ });
2699
+ });
2700
+ return dnsResolution;
2701
+ };
2702
+
2685
2703
  const createServerOrigin = ({
2686
2704
  protocol,
2687
2705
  hostname,
@@ -3536,7 +3554,7 @@ const startServer = async ({
3536
3554
  };
3537
3555
 
3538
3556
  status = "opened";
3539
- const serverOrigins = getServerOrigins({
3557
+ const serverOrigins = await getServerOrigins({
3540
3558
  protocol,
3541
3559
  ip,
3542
3560
  port
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "27.3.0",
3
+ "version": "27.3.1",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -73,7 +73,7 @@
73
73
  "@jsenv/integrity": "0.0.1",
74
74
  "@jsenv/log": "3.1.0",
75
75
  "@jsenv/node-esm-resolution": "0.1.0",
76
- "@jsenv/server": "12.7.5",
76
+ "@jsenv/server": "12.8.0",
77
77
  "@jsenv/sourcemap": "1.0.1",
78
78
  "@jsenv/uneval": "1.6.0",
79
79
  "@jsenv/url-meta": "7.0.0",