@lzwme/sserver 0.0.7 → 0.0.8
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 +6 -1
- package/dist/lib/utils.d.ts +1 -0
- package/dist/lib/utils.js +23 -0
- package/dist/static-server.js +5 -2
- package/package.json +10 -10
package/README.MD
CHANGED
|
@@ -11,12 +11,17 @@
|
|
|
11
11
|
|
|
12
12
|
一个基于 Node.js 的简易静态服务器,用于辅助开发调试随启随用。
|
|
13
13
|
|
|
14
|
+
```bash
|
|
15
|
+
# 快速启动一个静态服务器
|
|
16
|
+
npx @lzwme/sserver -d ./dist
|
|
17
|
+
```
|
|
18
|
+
|
|
14
19
|
## 安装
|
|
15
20
|
|
|
16
21
|
```bash
|
|
17
22
|
# 全局安装
|
|
18
23
|
npm i -g @lzwme/sserver
|
|
19
|
-
|
|
24
|
+
ss -h
|
|
20
25
|
|
|
21
26
|
# 或者在项目中安装
|
|
22
27
|
npm i -D @lzwme/sserver
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getIp(): string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getIp = void 0;
|
|
4
|
+
const os_1 = require("os");
|
|
5
|
+
function getIp() {
|
|
6
|
+
const nif = (0, os_1.networkInterfaces)();
|
|
7
|
+
let list = [];
|
|
8
|
+
for (const key of Object.keys(nif)) {
|
|
9
|
+
for (const item of nif[key]) {
|
|
10
|
+
if (!item.internal && item.address && item.family === 'IPv4')
|
|
11
|
+
list.push(item);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
list = list.sort((a, b) => {
|
|
15
|
+
if (b.address.startsWith('172.'))
|
|
16
|
+
return -1;
|
|
17
|
+
return 0;
|
|
18
|
+
});
|
|
19
|
+
// console.log(list);
|
|
20
|
+
return list[0]?.address;
|
|
21
|
+
}
|
|
22
|
+
exports.getIp = getIp;
|
|
23
|
+
// console.log(getIp());
|
package/dist/static-server.js
CHANGED
|
@@ -43,11 +43,13 @@ const config_1 = require("./config");
|
|
|
43
43
|
const get_logger_1 = require("./get-logger");
|
|
44
44
|
const express_proxy_1 = require("./proxy/express-proxy");
|
|
45
45
|
const php_proxy_1 = require("./proxy/php-proxy");
|
|
46
|
+
const utils_js_1 = require("./lib/utils.js");
|
|
46
47
|
async function initServer(c) {
|
|
47
48
|
const app = (0, express_1.default)();
|
|
48
49
|
const config = await (0, config_1.getConfig)(!c, c);
|
|
49
50
|
const { rootDir = '.', port = 8888, host = 'localhost' } = config;
|
|
50
51
|
const url = `http${config.https ? 's' : ''}://${host}:${port}`;
|
|
52
|
+
const ipUrl = `http://${(0, utils_js_1.getIp)()}:${port}`;
|
|
51
53
|
app.use((_req, res, next) => {
|
|
52
54
|
Object.entries(config.headers).forEach(([key, value]) => res.header(key, value));
|
|
53
55
|
next();
|
|
@@ -78,8 +80,9 @@ async function initServer(c) {
|
|
|
78
80
|
}));
|
|
79
81
|
}
|
|
80
82
|
const onListen = () => {
|
|
81
|
-
get_logger_1.logger.log(console_log_colors_1.color.green(`
|
|
82
|
-
get_logger_1.logger.log(console_log_colors_1.color.green(`
|
|
83
|
+
get_logger_1.logger.log(console_log_colors_1.color.green(`ROOT DIR : `.padStart(15, ' ')), console_log_colors_1.color.greenBright(rootDir));
|
|
84
|
+
get_logger_1.logger.log(console_log_colors_1.color.green(`Local/Host : `.padStart(15, ' ')), console_log_colors_1.color.cyanBright(url));
|
|
85
|
+
get_logger_1.logger.log(console_log_colors_1.color.green(`Network[IP] : `.padStart(15, ' ')), console_log_colors_1.color.cyanBright(ipUrl));
|
|
83
86
|
};
|
|
84
87
|
if (config.https) {
|
|
85
88
|
(0, node_https_1.createServer)(config.ssl, app).listen(port, onListen);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lzwme/sserver",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "一个基于 Node.js 的简易静态服务器,用于辅助开发调试随启随用",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": "^14.18.0 || >=16.15.0"
|
|
21
21
|
},
|
|
22
|
-
"packageManager": "pnpm@
|
|
22
|
+
"packageManager": "pnpm@8.2.0",
|
|
23
23
|
"keywords": [
|
|
24
24
|
"server",
|
|
25
25
|
"web-server",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"release": "npm run build"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@lzwme/fe-utils": "^1.5.
|
|
51
|
-
"commander": "^
|
|
50
|
+
"@lzwme/fe-utils": "^1.5.8",
|
|
51
|
+
"commander": "^11.1.0",
|
|
52
52
|
"console-log-colors": "^0.4.0",
|
|
53
53
|
"express": "^4.18.2",
|
|
54
54
|
"http-proxy-middleware": "^2.0.6",
|
|
@@ -56,13 +56,13 @@
|
|
|
56
56
|
"serve-index": "^1.9.1"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@lzwme/fed-lint-helper": "^2.
|
|
60
|
-
"@types/express": "^4.17.
|
|
61
|
-
"@types/node": "^20.
|
|
62
|
-
"@types/node-forge": "^1.3.
|
|
59
|
+
"@lzwme/fed-lint-helper": "^2.5.1",
|
|
60
|
+
"@types/express": "^4.17.21",
|
|
61
|
+
"@types/node": "^20.10.5",
|
|
62
|
+
"@types/node-forge": "^1.3.10",
|
|
63
63
|
"husky": "^8.0.3",
|
|
64
64
|
"standard-version": "^9.5.0",
|
|
65
|
-
"ts-node": "^10.9.
|
|
66
|
-
"typescript": "^5.
|
|
65
|
+
"ts-node": "^10.9.2",
|
|
66
|
+
"typescript": "^5.3.3"
|
|
67
67
|
}
|
|
68
68
|
}
|