@lzwme/sserver 0.0.6 → 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 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
- sserver -h
24
+ ss -h
20
25
 
21
26
  # 或者在项目中安装
22
27
  npm i -D @lzwme/sserver
package/dist/cli.js CHANGED
@@ -14,6 +14,7 @@ commander_1.program
14
14
  .description(console_log_colors_1.color.yellow(pkg.description) + ` [version@${console_log_colors_1.color.cyanBright(pkg.version)}]`)
15
15
  // .option('-c, --config-path [filepath]', `配置文件 ${color.yellow(config.configPath)} 的路径`)
16
16
  .option('-d, --root-dir [dirpath]', '静态服务器的根目录路径')
17
+ .option('-a, --autoindex', '是否开启目录列表浏览')
17
18
  .option('-p, --port [port]', '端口号')
18
19
  .option('--host <hostname>', '域名。默认为 `localhost`')
19
20
  .option('-H, --https', '启用 https 模式')
package/dist/config.d.ts CHANGED
@@ -6,6 +6,8 @@ import { type Options } from 'http-proxy-middleware';
6
6
  import { type Response, type Express } from 'express';
7
7
  import { type NLogger, type color } from '@lzwme/fe-utils';
8
8
  export interface SSConfig {
9
+ /** 是否开启目录列表 */
10
+ autoindex?: boolean;
9
11
  /** 自定义 app 应用逻辑 */
10
12
  custom?(app: Express, config: SSConfig, logger: NLogger, c: typeof color): void;
11
13
  /** host 地址。默认为 127.0.0.1 */
@@ -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());
@@ -6,25 +6,50 @@
6
6
  * @LastEditTime: 2023-02-03 13:32:07
7
7
  * @Description:
8
8
  */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
9
32
  var __importDefault = (this && this.__importDefault) || function (mod) {
10
33
  return (mod && mod.__esModule) ? mod : { "default": mod };
11
34
  };
12
35
  Object.defineProperty(exports, "__esModule", { value: true });
13
36
  exports.initServer = void 0;
14
37
  const node_https_1 = require("node:https");
38
+ const node_child_process_1 = require("node:child_process");
15
39
  const console_log_colors_1 = require("console-log-colors");
16
40
  const express_1 = __importDefault(require("express"));
17
- const child_process_1 = require("child_process");
18
41
  const fe_utils_1 = require("@lzwme/fe-utils");
19
42
  const config_1 = require("./config");
20
43
  const get_logger_1 = require("./get-logger");
21
44
  const express_proxy_1 = require("./proxy/express-proxy");
22
45
  const php_proxy_1 = require("./proxy/php-proxy");
46
+ const utils_js_1 = require("./lib/utils.js");
23
47
  async function initServer(c) {
24
48
  const app = (0, express_1.default)();
25
49
  const config = await (0, config_1.getConfig)(!c, c);
26
50
  const { rootDir = '.', port = 8888, host = 'localhost' } = config;
27
51
  const url = `http${config.https ? 's' : ''}://${host}:${port}`;
52
+ const ipUrl = `http://${(0, utils_js_1.getIp)()}:${port}`;
28
53
  app.use((_req, res, next) => {
29
54
  Object.entries(config.headers).forEach(([key, value]) => res.header(key, value));
30
55
  next();
@@ -46,9 +71,18 @@ async function initServer(c) {
46
71
  }
47
72
  },
48
73
  }));
74
+ if (config.autoindex) {
75
+ // @ts-expect-error
76
+ const serveIndex = await Promise.resolve().then(() => __importStar(require('serve-index')));
77
+ app.use(serveIndex.default(rootDir, {
78
+ icons: true,
79
+ hidden: true,
80
+ }));
81
+ }
49
82
  const onListen = () => {
50
- get_logger_1.logger.log(console_log_colors_1.color.green(`Runing at : `.padStart(15, ' ')), console_log_colors_1.color.cyanBright(url));
51
- get_logger_1.logger.log(console_log_colors_1.color.green(`ROOT DIR : `.padStart(15, ' ')), console_log_colors_1.color.cyanBright(rootDir));
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));
52
86
  };
53
87
  if (config.https) {
54
88
  (0, node_https_1.createServer)(config.ssl, app).listen(port, onListen);
@@ -59,7 +93,7 @@ async function initServer(c) {
59
93
  get_logger_1.logger.debug(config);
60
94
  if (config.open) {
61
95
  const openPageCmd = `${process.platform === 'win32' ? `start` : `open`} ${url}`;
62
- (0, child_process_1.execSync)(openPageCmd);
96
+ (0, node_child_process_1.execSync)(openPageCmd);
63
97
  }
64
98
  return app;
65
99
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lzwme/sserver",
3
- "version": "0.0.6",
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@7.2.0",
22
+ "packageManager": "pnpm@8.2.0",
23
23
  "keywords": [
24
24
  "server",
25
25
  "web-server",
@@ -47,21 +47,22 @@
47
47
  "release": "npm run build"
48
48
  },
49
49
  "dependencies": {
50
- "@lzwme/fe-utils": "^1.3.3",
51
- "commander": "^10.0.0",
52
- "console-log-colors": "^0.3.5",
50
+ "@lzwme/fe-utils": "^1.5.8",
51
+ "commander": "^11.1.0",
52
+ "console-log-colors": "^0.4.0",
53
53
  "express": "^4.18.2",
54
54
  "http-proxy-middleware": "^2.0.6",
55
- "node-forge": "^1.3.1"
55
+ "node-forge": "^1.3.1",
56
+ "serve-index": "^1.9.1"
56
57
  },
57
58
  "devDependencies": {
58
- "@lzwme/fed-lint-helper": "^2.2.0",
59
- "@types/express": "^4.17.16",
60
- "@types/node": "^18.11.18",
61
- "@types/node-forge": "^1.3.1",
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",
62
63
  "husky": "^8.0.3",
63
64
  "standard-version": "^9.5.0",
64
- "ts-node": "^10.9.1",
65
- "typescript": "^4.9.5"
65
+ "ts-node": "^10.9.2",
66
+ "typescript": "^5.3.3"
66
67
  }
67
68
  }