@lzwme/sserver 0.0.2 → 0.0.4
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 +3 -21
- package/dist/cli.js +11 -9
- package/dist/config.d.ts +2 -0
- package/dist/config.js +14 -7
- package/dist/get-logger.d.ts +2 -0
- package/dist/get-logger.js +9 -0
- package/dist/proxy/express-proxy.js +4 -3
- package/dist/proxy/socket-proxy.d.ts +1 -1
- package/dist/proxy/socket-proxy.js +3 -3
- package/dist/static-server.js +12 -8
- package/package.json +13 -8
- package/ss.config.sample.js +2 -2
- package/.eslintrc.js +0 -70
- package/.gitattributes +0 -3
- package/.husky/commit-msg +0 -4
- package/CHANGELOG.md +0 -17
package/README.MD
CHANGED
|
@@ -38,25 +38,7 @@ npx @lzwme/sserver -d ./dist
|
|
|
38
38
|
|
|
39
39
|
```bash
|
|
40
40
|
# 已当前目录下的 dist 作为静态目录
|
|
41
|
-
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
### 帮助信息
|
|
45
|
-
|
|
46
|
-
```bash
|
|
47
|
-
sserver -h
|
|
48
|
-
|
|
49
|
-
Usage: sserver|ss [options]
|
|
50
|
-
|
|
51
|
-
一个基于 nodejs 的简易静态服务器,方便随时调试使用 [version@1.0.0]
|
|
52
|
-
|
|
53
|
-
Options:
|
|
54
|
-
-v, --version output the version number
|
|
55
|
-
-d, --dir [rootDir] 静态服务器的根目录路径
|
|
56
|
-
-p, --port 端口号 (default: 8890)
|
|
57
|
-
-o, --open 启动后是否打开静态服务器首页
|
|
58
|
-
--debug 开启调试模式。 (default: false)
|
|
59
|
-
-h, --help display help for command
|
|
41
|
+
sserver -d ./dist
|
|
60
42
|
```
|
|
61
43
|
|
|
62
44
|
### 配置代理转发
|
|
@@ -72,14 +54,14 @@ module.exports = {
|
|
|
72
54
|
baseDir: './dist',
|
|
73
55
|
// 代理转发配置
|
|
74
56
|
proxyConfig: [
|
|
75
|
-
//
|
|
57
|
+
// 内网代理企业微信机器人接口示例
|
|
76
58
|
{
|
|
77
59
|
api: '/proxy/cgi-bin/webhook/send',
|
|
78
60
|
config: {
|
|
79
61
|
target: 'https://qyapi.weixin.qq.com',
|
|
80
62
|
changeOrigin: true,
|
|
81
63
|
pathRewrite: {
|
|
82
|
-
'^/proxy': '',
|
|
64
|
+
'^/proxy/cgi-bin': '/cgi-bin',
|
|
83
65
|
},
|
|
84
66
|
},
|
|
85
67
|
},
|
package/dist/cli.js
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
const commander_1 = require("commander");
|
|
7
|
-
const
|
|
4
|
+
const console_log_colors_1 = require("console-log-colors");
|
|
5
|
+
const config_1 = require("./config");
|
|
6
|
+
const get_logger_1 = require("./get-logger");
|
|
8
7
|
const static_server_1 = require("./static-server");
|
|
9
8
|
const pkg = require('../package.json');
|
|
10
9
|
commander_1.program
|
|
11
10
|
.aliases(['ss'])
|
|
12
11
|
.version(pkg.version, '-v, --version')
|
|
13
|
-
.description(
|
|
14
|
-
// .option('-c, --config-path [filepath]', `配置文件 ${
|
|
12
|
+
.description(console_log_colors_1.color.yellow(pkg.description) + ` [version@${console_log_colors_1.color.cyanBright(pkg.version)}]`)
|
|
13
|
+
// .option('-c, --config-path [filepath]', `配置文件 ${color.yellow(config.configPath)} 的路径`)
|
|
15
14
|
.option('-d, --base-dir [baseDir]', '静态服务器的根目录路径')
|
|
16
15
|
.option('-p, --port [port]', '端口号')
|
|
17
16
|
.option('-o, --open', '启动后是否打开静态服务器首页')
|
|
17
|
+
.option('--log [dirpath]', `指定日志路径`)
|
|
18
18
|
.option('--debug', `开启调试模式。`, false)
|
|
19
19
|
.action(opts => {
|
|
20
|
-
if (opts.debug)
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
if (opts.debug) {
|
|
21
|
+
get_logger_1.logger.updateOptions({ levelType: 'debug' });
|
|
22
|
+
get_logger_1.logger.debug(opts);
|
|
23
|
+
}
|
|
24
|
+
(0, static_server_1.initServer)((0, config_1.getConfig)(false, opts));
|
|
23
25
|
});
|
|
24
26
|
commander_1.program.parse(process.argv);
|
package/dist/config.d.ts
CHANGED
|
@@ -11,5 +11,7 @@ export interface SSConfig {
|
|
|
11
11
|
api: string;
|
|
12
12
|
config: Options;
|
|
13
13
|
}[];
|
|
14
|
+
/** 是否开启日志记录。默认为 false。若设置为 true 则默认为 ~/.sserver/log.log;若为字符串,则设置为日志路径 */
|
|
15
|
+
log?: boolean | string;
|
|
14
16
|
}
|
|
15
17
|
export declare function getConfig(useCache?: boolean, cfg?: SSConfig): SSConfig;
|
package/dist/config.js
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getConfig = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const node_os_1 = require("node:os");
|
|
6
|
+
const node_fs_1 = require("node:fs");
|
|
7
|
+
const fe_utils_1 = require("@lzwme/fe-utils");
|
|
8
|
+
const get_logger_1 = require("./get-logger");
|
|
6
9
|
const ssConfig = {
|
|
7
10
|
baseDir: '.',
|
|
8
|
-
open:
|
|
11
|
+
open: false,
|
|
9
12
|
port: 8890,
|
|
10
13
|
proxyConfig: [],
|
|
14
|
+
log: false,
|
|
11
15
|
};
|
|
12
16
|
function getConfig(useCache = true, cfg) {
|
|
13
17
|
if (ssConfig.port && useCache)
|
|
14
18
|
return ssConfig;
|
|
15
|
-
const cfgFile = (0,
|
|
16
|
-
if ((0,
|
|
17
|
-
|
|
19
|
+
const cfgFile = (0, node_path_1.resolve)(process.cwd(), './ss.config.js');
|
|
20
|
+
if ((0, node_fs_1.existsSync)(cfgFile))
|
|
21
|
+
(0, fe_utils_1.assign)(ssConfig, require(cfgFile));
|
|
18
22
|
if (cfg)
|
|
19
|
-
|
|
23
|
+
(0, fe_utils_1.assign)(ssConfig, cfg);
|
|
24
|
+
if (ssConfig.log) {
|
|
25
|
+
get_logger_1.logger.setLogDir(typeof ssConfig.log === 'boolean' ? (0, node_path_1.resolve)((0, node_os_1.homedir)(), '.sserver/log.log') : ssConfig.log);
|
|
26
|
+
}
|
|
20
27
|
return ssConfig;
|
|
21
28
|
}
|
|
22
29
|
exports.getConfig = getConfig;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logger = void 0;
|
|
4
|
+
const console_log_colors_1 = require("console-log-colors");
|
|
5
|
+
const fe_utils_1 = require("@lzwme/fe-utils");
|
|
6
|
+
function getLogger(levelType, logDir) {
|
|
7
|
+
return fe_utils_1.NLogger.getLogger('[sserver]', { levelType, color: console_log_colors_1.color, logDir });
|
|
8
|
+
}
|
|
9
|
+
exports.logger = getLogger();
|
|
@@ -4,20 +4,21 @@ exports.proxyByExpress = void 0;
|
|
|
4
4
|
const console_log_colors_1 = require("console-log-colors");
|
|
5
5
|
const http_proxy_middleware_1 = require("http-proxy-middleware");
|
|
6
6
|
const config_1 = require("../config");
|
|
7
|
+
const get_logger_1 = require("../get-logger");
|
|
7
8
|
function proxyByExpress(app) {
|
|
8
9
|
const { proxyConfig } = (0, config_1.getConfig)();
|
|
9
|
-
if (!proxyConfig)
|
|
10
|
+
if (!proxyConfig?.length)
|
|
10
11
|
return;
|
|
11
12
|
proxyConfig.forEach(({ api, config }) => {
|
|
12
13
|
const onProxyReq = config.onProxyReq;
|
|
13
14
|
config.onProxyReq = (pReq, req, res, options) => {
|
|
14
15
|
const now = new Date();
|
|
15
|
-
|
|
16
|
+
get_logger_1.logger.log(now.toTimeString().slice(0, 8) + '.' + String(now.getMilliseconds()).padStart(3, '0'), console_log_colors_1.color.gray('[proxyReq]'), console_log_colors_1.color.cyan(req.originalUrl), '=>', console_log_colors_1.color.cyanBright(`${pReq.protocol}${pReq.host}${pReq.path}`));
|
|
16
17
|
if (onProxyReq)
|
|
17
18
|
onProxyReq(pReq, req, res, options);
|
|
18
19
|
};
|
|
19
20
|
app.use(api, (0, http_proxy_middleware_1.createProxyMiddleware)(config));
|
|
20
|
-
|
|
21
|
+
get_logger_1.logger.log(`Init proxy for ${console_log_colors_1.color.cyanBright(api)}`);
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
exports.proxyByExpress = proxyByExpress;
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.socketProxy = void 0;
|
|
7
|
-
const
|
|
7
|
+
const node_net_1 = __importDefault(require("node:net"));
|
|
8
8
|
const console_log_colors_1 = require("console-log-colors");
|
|
9
9
|
function socketProxy(config = {
|
|
10
10
|
// 外网访问的端口
|
|
@@ -14,10 +14,10 @@ function socketProxy(config = {
|
|
|
14
14
|
//代理转发的 IP 地址
|
|
15
15
|
remoteHost: '127.0.0.1',
|
|
16
16
|
}) {
|
|
17
|
-
const server =
|
|
17
|
+
const server = node_net_1.default
|
|
18
18
|
.createServer(socket => {
|
|
19
19
|
console_log_colors_1.log.green('proxy for address', socket.address());
|
|
20
|
-
let to =
|
|
20
|
+
let to = node_net_1.default.createConnection({
|
|
21
21
|
host: config.remoteHost,
|
|
22
22
|
port: config.remotePort,
|
|
23
23
|
});
|
package/dist/static-server.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint-disable no-console */
|
|
3
2
|
/*
|
|
4
3
|
* @Author: lzw
|
|
5
4
|
* @Date: 2021-05-28 16:24:40
|
|
6
5
|
* @LastEditors: lzw
|
|
7
|
-
* @LastEditTime: 2022-
|
|
6
|
+
* @LastEditTime: 2022-09-23 17:21:36
|
|
8
7
|
* @Description:
|
|
9
8
|
*/
|
|
10
9
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
@@ -12,27 +11,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
11
|
};
|
|
13
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
13
|
exports.initServer = void 0;
|
|
14
|
+
const node_path_1 = require("node:path");
|
|
15
15
|
const console_log_colors_1 = require("console-log-colors");
|
|
16
16
|
const express_1 = __importDefault(require("express"));
|
|
17
17
|
const child_process_1 = require("child_process");
|
|
18
18
|
const config_1 = require("./config");
|
|
19
19
|
const express_proxy_1 = require("./proxy/express-proxy");
|
|
20
|
+
const get_logger_1 = require("./get-logger");
|
|
20
21
|
function initServer(options) {
|
|
21
22
|
options = (0, config_1.getConfig)(true, options);
|
|
22
23
|
const app = (0, express_1.default)();
|
|
23
|
-
const {
|
|
24
|
+
const { port = 8890 } = options;
|
|
25
|
+
const baseDir = (0, node_path_1.resolve)(process.cwd(), typeof options.baseDir === 'string' ? options.baseDir : '.');
|
|
24
26
|
// @see https://www.expressjs.com.cn/4x/api.html#express.static
|
|
25
|
-
app.use(express_1.default.static(baseDir
|
|
27
|
+
app.use(express_1.default.static(baseDir, {
|
|
28
|
+
// extensions: ['html', 'htm'],
|
|
29
|
+
}));
|
|
26
30
|
(0, express_proxy_1.proxyByExpress)(app);
|
|
27
31
|
app.listen(port, () => {
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
get_logger_1.logger.log(console_log_colors_1.color.green(`Listening On:`), port);
|
|
33
|
+
get_logger_1.logger.log(console_log_colors_1.color.green(`ROOT DIR:`), console_log_colors_1.color.cyanBright(baseDir));
|
|
30
34
|
});
|
|
31
|
-
|
|
35
|
+
get_logger_1.logger.debug(options);
|
|
36
|
+
if (options.open) {
|
|
32
37
|
const openPageCmd = `${process.platform === 'win32' ? `start` : `open`} http://localhost:${port}`;
|
|
33
38
|
(0, child_process_1.execSync)(openPageCmd);
|
|
34
39
|
}
|
|
35
40
|
return app;
|
|
36
41
|
}
|
|
37
42
|
exports.initServer = initServer;
|
|
38
|
-
;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lzwme/sserver",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "一个基于 nodejs 的简易静态服务器,方便随时开发调试使用",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"private": false,
|
|
19
19
|
"engines": {
|
|
20
|
-
"node": ">=
|
|
20
|
+
"node": "^14.18.0 || >=16.15.0"
|
|
21
21
|
},
|
|
22
22
|
"packageManager": "pnpm@7.2.0",
|
|
23
23
|
"keywords": [
|
|
@@ -30,6 +30,10 @@
|
|
|
30
30
|
"access": "public",
|
|
31
31
|
"registry": "https://registry.npmjs.com"
|
|
32
32
|
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"ss.config.sample.js"
|
|
36
|
+
],
|
|
33
37
|
"scripts": {
|
|
34
38
|
"prepare": "husky install",
|
|
35
39
|
"ss": "node bin/sserver.js",
|
|
@@ -41,18 +45,19 @@
|
|
|
41
45
|
"version": "standard-version"
|
|
42
46
|
},
|
|
43
47
|
"dependencies": {
|
|
44
|
-
"
|
|
48
|
+
"@lzwme/fe-utils": "^1.0.0",
|
|
49
|
+
"commander": "^9.4.0",
|
|
45
50
|
"console-log-colors": "^0.2.3",
|
|
46
51
|
"express": "^4.18.1",
|
|
47
52
|
"http-proxy-middleware": "^2.0.6"
|
|
48
53
|
},
|
|
49
54
|
"devDependencies": {
|
|
50
|
-
"@lzwme/fed-lint-helper": "^
|
|
51
|
-
"@types/express": "^4.17.
|
|
52
|
-
"@types/node": "^18.
|
|
55
|
+
"@lzwme/fed-lint-helper": "^2.0.1",
|
|
56
|
+
"@types/express": "^4.17.14",
|
|
57
|
+
"@types/node": "^18.7.18",
|
|
53
58
|
"husky": "^8.0.1",
|
|
54
59
|
"standard-version": "^9.5.0",
|
|
55
|
-
"ts-node": "^10.
|
|
56
|
-
"typescript": "^4.
|
|
60
|
+
"ts-node": "^10.9.1",
|
|
61
|
+
"typescript": "^4.8.3"
|
|
57
62
|
}
|
|
58
63
|
}
|
package/ss.config.sample.js
CHANGED
|
@@ -3,14 +3,14 @@ module.exports = {
|
|
|
3
3
|
port: 8890,
|
|
4
4
|
baseDir: '.',
|
|
5
5
|
proxyConfig: [
|
|
6
|
-
//
|
|
6
|
+
// 内网代理企业微信机器人接口示例
|
|
7
7
|
{
|
|
8
8
|
api: '/proxy/cgi-bin/webhook/send',
|
|
9
9
|
config: {
|
|
10
10
|
target: 'https://qyapi.weixin.qq.com',
|
|
11
11
|
changeOrigin: true,
|
|
12
12
|
pathRewrite: {
|
|
13
|
-
'^/proxy': '',
|
|
13
|
+
'^/proxy/cgi-bin': '/cgi-bin',
|
|
14
14
|
},
|
|
15
15
|
},
|
|
16
16
|
},
|
package/.eslintrc.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const rootDir = path.resolve(__dirname);
|
|
4
|
-
|
|
5
|
-
/** @type {import('eslint').Linter.Config} */
|
|
6
|
-
module.exports = {
|
|
7
|
-
extends: [
|
|
8
|
-
'eslint:recommended',
|
|
9
|
-
// https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/docs/getting-started/linting/README.md
|
|
10
|
-
'plugin:@typescript-eslint/recommended',
|
|
11
|
-
// 'plugin:@typescript-eslint/recommended-requiring-type-checking',
|
|
12
|
-
'plugin:prettier/recommended',
|
|
13
|
-
'plugin:jest/recommended',
|
|
14
|
-
'plugin:unicorn/recommended',
|
|
15
|
-
],
|
|
16
|
-
env: {
|
|
17
|
-
browser: true,
|
|
18
|
-
es2021: true,
|
|
19
|
-
node: true,
|
|
20
|
-
},
|
|
21
|
-
globals: {
|
|
22
|
-
SharedArrayBuffer: 'readonly',
|
|
23
|
-
},
|
|
24
|
-
parser: '@typescript-eslint/parser',
|
|
25
|
-
parserOptions: {
|
|
26
|
-
tsconfigRootDir: rootDir,
|
|
27
|
-
project: path.resolve(rootDir, './tsconfig.eslint.json'),
|
|
28
|
-
projectFolderIgnoreList: ['**/node_modules/**', '**/dist/**', '**/dist-admin/**'],
|
|
29
|
-
warnOnUnsupportedTypeScriptVersion: false,
|
|
30
|
-
// createDefaultProgram: true,
|
|
31
|
-
ecmaFeatures: {
|
|
32
|
-
jsx: true,
|
|
33
|
-
},
|
|
34
|
-
ecmaVersion: 2020,
|
|
35
|
-
sourceType: 'module',
|
|
36
|
-
},
|
|
37
|
-
plugins: ['@typescript-eslint'],
|
|
38
|
-
ignorePatterns: [
|
|
39
|
-
'**/node_modules/**',
|
|
40
|
-
'dist/**',
|
|
41
|
-
'build/**',
|
|
42
|
-
'mock/**',
|
|
43
|
-
'**/*.js',
|
|
44
|
-
'**/*.d.ts',
|
|
45
|
-
],
|
|
46
|
-
rules: {
|
|
47
|
-
'prettier/prettier': 'warn',
|
|
48
|
-
// 关闭 eslint 的 indent,使用 prettier 格式化格式
|
|
49
|
-
indent: ['off', 2],
|
|
50
|
-
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
51
|
-
'@typescript-eslint/no-unused-vars': ['warn', { varsIgnorePattern: '^_', argsIgnorePattern: '^_', ignoreRestSiblings: true }],
|
|
52
|
-
'@typescript-eslint/ban-ts-comment': 'off',
|
|
53
|
-
'unicorn/prefer-module': 'off',
|
|
54
|
-
'unicorn/prefer-node-protocol': 'off',
|
|
55
|
-
'unicorn/no-nested-ternary': 'off',
|
|
56
|
-
'unicorn/no-process-exit': 'off',
|
|
57
|
-
'unicorn/consistent-destructuring': 'off',
|
|
58
|
-
'jest/no-export': 'off',
|
|
59
|
-
'unicorn/filename-case': 'off',
|
|
60
|
-
'unicorn/no-null': 'off',
|
|
61
|
-
'unicorn/prevent-abbreviations': 'off',
|
|
62
|
-
'unicorn/import-style': ['error', {
|
|
63
|
-
styles: {
|
|
64
|
-
path: {
|
|
65
|
-
named: true,
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}]
|
|
69
|
-
},
|
|
70
|
-
};
|
package/.gitattributes
DELETED
package/.husky/commit-msg
DELETED
package/CHANGELOG.md
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
-
|
|
5
|
-
### [0.0.2](https://github.com/lzwme/static-server/compare/v0.0.1...v0.0.2) (2022-09-15)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
### Bug Fixes
|
|
9
|
-
|
|
10
|
-
* fix for cli error ([ce32f27](https://github.com/lzwme/static-server/commit/ce32f27f6658234bd888021a6a9cb3c12f151022))
|
|
11
|
-
|
|
12
|
-
### 0.0.1 (2022-07-01)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
### Features
|
|
16
|
-
|
|
17
|
-
* 新增代理转发支持;使用 ts 重构 ([9d6a960](https://github.com/lzwme/static-server/commit/9d6a960c0a311f1f345f5e9c7b544161920fbae2))
|