skybase 0.1.111 → 0.1.113
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/CHANGELOG.md +14 -0
- package/lib/sky.js +31 -54
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [0.1.112](https://github.com/kongnet/skybase/compare/v0.1.111...v0.1.112) (2026-10-23)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### :zap:
|
|
5
|
+
|
|
6
|
+
* add koa ipaddress support ([f2ad010](https://github.com/kongnet/skybase/commit/f2ad010c99b9c44c4111c0d6e27e61551e39a6c5))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## [0.1.111](https://github.com/kongnet/skybase/compare/v0.1.110...v0.1.111) (2026-06-03)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
1
15
|
## [0.1.110](https://github.com/kongnet/skybase/compare/v0.1.109...v0.1.110) (2026-06-03)
|
|
2
16
|
|
|
3
17
|
|
package/lib/sky.js
CHANGED
|
@@ -1,29 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict'
|
|
3
|
-
const os = require('os')
|
|
4
|
-
|
|
5
|
-
const networkInterfaces = os.networkInterfaces()
|
|
6
|
-
let localIP = Object.keys(networkInterfaces).map((ifname, index) => {
|
|
7
|
-
const iface = networkInterfaces[ifname]
|
|
8
|
-
const arr = iface.map(x => {
|
|
9
|
-
if (
|
|
10
|
-
x?.family === 'IPv4' &&
|
|
11
|
-
!x?.internal &&
|
|
12
|
-
x?.mac !== '00:00:00:00:00:00'
|
|
13
|
-
) {
|
|
14
|
-
return x.address
|
|
15
|
-
}
|
|
16
|
-
})
|
|
17
|
-
return arr.filter(Boolean)
|
|
18
|
-
})
|
|
19
|
-
|
|
20
3
|
const $G = (global.$G = global.$G || {})
|
|
21
4
|
// global.Promise = require('bluebird')
|
|
22
5
|
|
|
23
6
|
const skyExt = require('./sky_extend')
|
|
24
7
|
const path = require('path')
|
|
25
8
|
const http = require('http')
|
|
26
|
-
const https = require('https')
|
|
27
9
|
|
|
28
10
|
// 全局对象
|
|
29
11
|
const $ = (global.$ = require('meeko'))
|
|
@@ -72,36 +54,34 @@ const getPort = async (port, beforeListenPort) => {
|
|
|
72
54
|
return portTemp
|
|
73
55
|
}
|
|
74
56
|
|
|
75
|
-
const createWebServer = async (port,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
server = http.createServer(app.callback())
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (afterCreateServer) {
|
|
86
|
-
await afterCreateServer(server)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
server.on('error', e => {
|
|
90
|
-
if (e.code === 'EADDRINUSE') {
|
|
91
|
-
$.err(
|
|
92
|
-
$.c.r('✘'),
|
|
93
|
-
`:${port} 端口已被占用\n检查方式(仅供参考):\nss -lntpd | grep :${port}\nlsof -i tcp:${port}`
|
|
94
|
-
)
|
|
95
|
-
} else {
|
|
96
|
-
$.err($.c.r('✘'), '服务发送错误', {
|
|
97
|
-
code: e.code,
|
|
98
|
-
message: e.message
|
|
99
|
-
})
|
|
57
|
+
const createWebServer = async (port, ip, afterCreateServer) => {
|
|
58
|
+
const serverList = []
|
|
59
|
+
ip = [].concat(ip)
|
|
60
|
+
ip.map(async it => {
|
|
61
|
+
const server = http.createServer(app.callback())
|
|
62
|
+
if (afterCreateServer) {
|
|
63
|
+
await afterCreateServer(server)
|
|
100
64
|
}
|
|
65
|
+
|
|
66
|
+
server.on('error', e => {
|
|
67
|
+
if (e.code === 'EADDRINUSE') {
|
|
68
|
+
$.err(
|
|
69
|
+
$.c.r('✘'),
|
|
70
|
+
`:${port} 端口已被占用\n检查方式(仅供参考):\nss -lntpd | grep :${port}\nlsof -i tcp:${port}`
|
|
71
|
+
)
|
|
72
|
+
} else {
|
|
73
|
+
$.err($.c.r('✘'), '服务发送错误', {
|
|
74
|
+
code: e.code,
|
|
75
|
+
message: e.message
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
console.log('Listen..', it, port)
|
|
80
|
+
server.listen(port, it)
|
|
81
|
+
serverList.push(server)
|
|
101
82
|
})
|
|
102
83
|
|
|
103
|
-
|
|
104
|
-
return server
|
|
84
|
+
return serverList
|
|
105
85
|
}
|
|
106
86
|
|
|
107
87
|
async function init (option, cbFun) {
|
|
@@ -110,7 +90,7 @@ async function init (option, cbFun) {
|
|
|
110
90
|
const {
|
|
111
91
|
name,
|
|
112
92
|
port,
|
|
113
|
-
|
|
93
|
+
ipAddress,
|
|
114
94
|
beforeMount,
|
|
115
95
|
beforeLoadMiddlewares,
|
|
116
96
|
afterLoadMiddlewares,
|
|
@@ -121,7 +101,7 @@ async function init (option, cbFun) {
|
|
|
121
101
|
rootDir,
|
|
122
102
|
middlewareDir
|
|
123
103
|
} = config
|
|
124
|
-
|
|
104
|
+
let ip = ipAddress || '0.0.0.0'
|
|
125
105
|
if (beforeMount) {
|
|
126
106
|
skyExt.artStage('beforeMount')
|
|
127
107
|
await beforeMount(config)
|
|
@@ -183,15 +163,12 @@ async function init (option, cbFun) {
|
|
|
183
163
|
|
|
184
164
|
// 侦听端口
|
|
185
165
|
const portFinal = await getPort(port, beforeListenPort)
|
|
186
|
-
$G.server = await createWebServer(portFinal,
|
|
166
|
+
$G.server = await createWebServer(portFinal, ip, afterCreateServer)
|
|
167
|
+
|
|
187
168
|
$.log(
|
|
188
169
|
$.c.g('✔'),
|
|
189
|
-
`${$.c.y(name)} WebServer [${$.c.y(
|
|
190
|
-
|
|
191
|
-
.join(',')}] Listen at`,
|
|
192
|
-
`${$.c.y(portFinal)} ${
|
|
193
|
-
https ? 'https' : 'http'
|
|
194
|
-
}://127.0.0.1:${portFinal}/`
|
|
170
|
+
`${$.c.y(name)} WebServer [${$.c.y(ip)}] Listen at`,
|
|
171
|
+
`${$.c.y(portFinal)}`
|
|
195
172
|
)
|
|
196
173
|
skyExt.artTxt(name, 'Graceful')
|
|
197
174
|
}
|