@lzwme/sserver 0.0.5 → 0.0.7
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/LICENSE +21 -21
- package/bin/sserver.js +0 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +62 -54
- package/dist/config.d.ts +49 -27
- package/dist/config.js +61 -49
- package/dist/get-logger.d.ts +2 -2
- package/dist/get-logger.js +9 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -5
- package/dist/lib/get-cert.d.ts +6 -6
- package/dist/lib/get-cert.js +79 -79
- package/dist/lib/mkcert.d.ts +26 -26
- package/dist/lib/mkcert.js +86 -86
- package/dist/proxy/express-proxy.d.ts +2 -2
- package/dist/proxy/express-proxy.js +24 -24
- package/dist/proxy/php-proxy.d.ts +3 -0
- package/dist/proxy/php-proxy.js +188 -0
- package/dist/proxy/socket-proxy.d.ts +7 -7
- package/dist/proxy/socket-proxy.js +30 -30
- package/dist/static-server.d.ts +3 -3
- package/dist/static-server.js +97 -50
- package/package.json +12 -11
package/dist/static-server.js
CHANGED
|
@@ -1,50 +1,97 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @Author: lzw
|
|
4
|
-
* @Date: 2021-05-28 16:24:40
|
|
5
|
-
* @LastEditors: lzw
|
|
6
|
-
* @LastEditTime:
|
|
7
|
-
* @Description:
|
|
8
|
-
*/
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* @Author: lzw
|
|
4
|
+
* @Date: 2021-05-28 16:24:40
|
|
5
|
+
* @LastEditors: lzw
|
|
6
|
+
* @LastEditTime: 2023-02-03 13:32:07
|
|
7
|
+
* @Description:
|
|
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
|
+
};
|
|
32
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
33
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
34
|
+
};
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.initServer = void 0;
|
|
37
|
+
const node_https_1 = require("node:https");
|
|
38
|
+
const node_child_process_1 = require("node:child_process");
|
|
39
|
+
const console_log_colors_1 = require("console-log-colors");
|
|
40
|
+
const express_1 = __importDefault(require("express"));
|
|
41
|
+
const fe_utils_1 = require("@lzwme/fe-utils");
|
|
42
|
+
const config_1 = require("./config");
|
|
43
|
+
const get_logger_1 = require("./get-logger");
|
|
44
|
+
const express_proxy_1 = require("./proxy/express-proxy");
|
|
45
|
+
const php_proxy_1 = require("./proxy/php-proxy");
|
|
46
|
+
async function initServer(c) {
|
|
47
|
+
const app = (0, express_1.default)();
|
|
48
|
+
const config = await (0, config_1.getConfig)(!c, c);
|
|
49
|
+
const { rootDir = '.', port = 8888, host = 'localhost' } = config;
|
|
50
|
+
const url = `http${config.https ? 's' : ''}://${host}:${port}`;
|
|
51
|
+
app.use((_req, res, next) => {
|
|
52
|
+
Object.entries(config.headers).forEach(([key, value]) => res.header(key, value));
|
|
53
|
+
next();
|
|
54
|
+
});
|
|
55
|
+
if (typeof config.custom === 'function') {
|
|
56
|
+
await config.custom(app, config, get_logger_1.logger, console_log_colors_1.color);
|
|
57
|
+
}
|
|
58
|
+
await (0, php_proxy_1.phpProxy)(app, config);
|
|
59
|
+
await (0, express_proxy_1.proxyByExpress)(app);
|
|
60
|
+
// @see https://www.expressjs.com.cn/4x/api.html#express.static
|
|
61
|
+
app.use(express_1.default.static(rootDir, {
|
|
62
|
+
extensions: ['html', 'htm'],
|
|
63
|
+
setHeaders: (res, path, stat) => {
|
|
64
|
+
if (typeof config.setHeaders === 'function') {
|
|
65
|
+
const headers = { ...config.headers };
|
|
66
|
+
get_logger_1.logger.debug('[setHeader]', path, headers);
|
|
67
|
+
(0, fe_utils_1.assign)(headers, config.setHeaders(res, path, stat));
|
|
68
|
+
Object.entries(headers).forEach(([key, value]) => res.header(key, value));
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
}));
|
|
72
|
+
if (config.autoindex) {
|
|
73
|
+
// @ts-expect-error
|
|
74
|
+
const serveIndex = await Promise.resolve().then(() => __importStar(require('serve-index')));
|
|
75
|
+
app.use(serveIndex.default(rootDir, {
|
|
76
|
+
icons: true,
|
|
77
|
+
hidden: true,
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
const onListen = () => {
|
|
81
|
+
get_logger_1.logger.log(console_log_colors_1.color.green(`Runing at : `.padStart(15, ' ')), console_log_colors_1.color.cyanBright(url));
|
|
82
|
+
get_logger_1.logger.log(console_log_colors_1.color.green(`ROOT DIR : `.padStart(15, ' ')), console_log_colors_1.color.cyanBright(rootDir));
|
|
83
|
+
};
|
|
84
|
+
if (config.https) {
|
|
85
|
+
(0, node_https_1.createServer)(config.ssl, app).listen(port, onListen);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
app.listen(port, onListen);
|
|
89
|
+
}
|
|
90
|
+
get_logger_1.logger.debug(config);
|
|
91
|
+
if (config.open) {
|
|
92
|
+
const openPageCmd = `${process.platform === 'win32' ? `start` : `open`} ${url}`;
|
|
93
|
+
(0, node_child_process_1.execSync)(openPageCmd);
|
|
94
|
+
}
|
|
95
|
+
return app;
|
|
96
|
+
}
|
|
97
|
+
exports.initServer = initServer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lzwme/sserver",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "一个基于 Node.js 的简易静态服务器,用于辅助开发调试随启随用",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -47,21 +47,22 @@
|
|
|
47
47
|
"release": "npm run build"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@lzwme/fe-utils": "^1.
|
|
51
|
-
"commander": "^
|
|
52
|
-
"console-log-colors": "^0.
|
|
50
|
+
"@lzwme/fe-utils": "^1.5.1",
|
|
51
|
+
"commander": "^10.0.1",
|
|
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.
|
|
59
|
-
"@types/express": "^4.17.
|
|
60
|
-
"@types/node": "^
|
|
61
|
-
"@types/node-forge": "^1.3.
|
|
62
|
-
"husky": "^8.0.
|
|
59
|
+
"@lzwme/fed-lint-helper": "^2.3.2",
|
|
60
|
+
"@types/express": "^4.17.17",
|
|
61
|
+
"@types/node": "^20.3.1",
|
|
62
|
+
"@types/node-forge": "^1.3.2",
|
|
63
|
+
"husky": "^8.0.3",
|
|
63
64
|
"standard-version": "^9.5.0",
|
|
64
65
|
"ts-node": "^10.9.1",
|
|
65
|
-
"typescript": "^
|
|
66
|
+
"typescript": "^5.1.3"
|
|
66
67
|
}
|
|
67
68
|
}
|