@jsenv/server 13.0.0 → 14.1.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/README.md +18 -51
- package/package.json +3 -2
- package/src/fetch_filesystem.js +2 -2
- package/src/internal/hostname_parser.js +48 -0
- package/src/internal/listen.js +11 -11
- package/src/internal/nodeStreamToObservable.js +1 -1
- package/src/internal/request_factory.js +16 -14
- package/src/internal/server-polyglot.js +1 -0
- package/src/internal/server_ips.js +49 -0
- package/src/main.js +2 -2
- package/src/service_controller.js +1 -0
- package/src/services/request_aliases/jsenv_service_request_aliases.js +37 -0
- package/src/sse/sse_room.js +1 -3
- package/src/start_server.js +1045 -0
- package/src/internal/getServerOrigins.js +0 -74
- package/src/server.js +0 -896
- package/src/services/ressource_aliases/jsenv_service_ressource_aliases.js +0 -40
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { networkInterfaces } from "node:os"
|
|
2
|
-
|
|
3
|
-
import { applyDnsResolution } from "./dns_resolution.js"
|
|
4
|
-
|
|
5
|
-
export const getServerOrigins = async ({ protocol, host, port }) => {
|
|
6
|
-
const isLocal = LOOPBACK_HOSTNAMES.includes(host)
|
|
7
|
-
const localhostDnsResolution = await applyDnsResolution("localhost")
|
|
8
|
-
const localOrigin = createServerOrigin({
|
|
9
|
-
protocol,
|
|
10
|
-
hostname:
|
|
11
|
-
localhostDnsResolution.address === "127.0.0.1"
|
|
12
|
-
? "localhost"
|
|
13
|
-
: "127.0.0.1",
|
|
14
|
-
port,
|
|
15
|
-
})
|
|
16
|
-
if (isLocal) {
|
|
17
|
-
return { local: localOrigin }
|
|
18
|
-
}
|
|
19
|
-
const isAnyIp = WILDCARD_HOSTNAMES.includes(host)
|
|
20
|
-
const networkOrigin = createServerOrigin({
|
|
21
|
-
protocol,
|
|
22
|
-
hostname: isAnyIp ? getExternalIp() : host,
|
|
23
|
-
port,
|
|
24
|
-
})
|
|
25
|
-
return {
|
|
26
|
-
local: localOrigin,
|
|
27
|
-
network: networkOrigin,
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const LOOPBACK_HOSTNAMES = [
|
|
32
|
-
"localhost",
|
|
33
|
-
"127.0.0.1",
|
|
34
|
-
"::1",
|
|
35
|
-
"0000:0000:0000:0000:0000:0000:0000:0001",
|
|
36
|
-
]
|
|
37
|
-
|
|
38
|
-
const WILDCARD_HOSTNAMES = [
|
|
39
|
-
undefined,
|
|
40
|
-
"0.0.0.0",
|
|
41
|
-
"::",
|
|
42
|
-
"0000:0000:0000:0000:0000:0000:0000:0000",
|
|
43
|
-
]
|
|
44
|
-
|
|
45
|
-
const createServerOrigin = ({ protocol, hostname, port }) => {
|
|
46
|
-
const url = new URL("https://127.0.0.1:80")
|
|
47
|
-
url.protocol = protocol
|
|
48
|
-
url.hostname = hostname
|
|
49
|
-
url.port = port
|
|
50
|
-
return url.origin
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const getExternalIp = () => {
|
|
54
|
-
const networkInterfaceMap = networkInterfaces()
|
|
55
|
-
let internalIPV4NetworkAddress
|
|
56
|
-
Object.keys(networkInterfaceMap).find((key) => {
|
|
57
|
-
const networkAddressArray = networkInterfaceMap[key]
|
|
58
|
-
return networkAddressArray.find((networkAddress) => {
|
|
59
|
-
if (networkAddress.internal) return false
|
|
60
|
-
if (!isIpV4(networkAddress)) return false
|
|
61
|
-
internalIPV4NetworkAddress = networkAddress
|
|
62
|
-
return true
|
|
63
|
-
})
|
|
64
|
-
})
|
|
65
|
-
return internalIPV4NetworkAddress ? internalIPV4NetworkAddress.address : null
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const isIpV4 = (networkAddress) => {
|
|
69
|
-
// node 18+
|
|
70
|
-
if (typeof networkAddress.family === "number") {
|
|
71
|
-
return networkAddress.family === 4
|
|
72
|
-
}
|
|
73
|
-
return networkAddress.family === "IPv4"
|
|
74
|
-
}
|