@yinuo-ngm/server 1.0.20 → 1.0.22
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/lib/app.js +0 -4
- package/lib/env.js +5 -1
- package/lib/plugins/success-handle.plugin.js +1 -1
- package/lib/plugins/ws/topics/nginx.ws.js +1 -1
- package/lib/plugins/ws/ws.context.js +3 -1
- package/lib/plugins/ws/ws.plugin.js +14 -2
- package/lib/routes/api-client/collection.routes.js +35 -35
- package/lib/routes/api-client/env.routes.js +12 -8
- package/lib/routes/api-client/history.routes.js +10 -5
- package/lib/routes/api-client/request.routes.js +14 -8
- package/lib/routes/api-client/route-mappers.d.ts +7 -0
- package/lib/routes/api-client/route-mappers.js +78 -0
- package/lib/routes/api-client/send.routes.js +12 -8
- package/lib/routes/config.routes.js +73 -49
- package/lib/routes/deps.route.js +47 -5
- package/lib/routes/index.js +5 -3
- package/lib/routes/nginx/nginx-config.routes.js +3 -3
- package/lib/routes/nginx/nginx-lifecycle.routes.js +14 -13
- package/lib/routes/nginx/nginx-module.routes.js +6 -6
- package/lib/routes/nginx/nginx-route.context.d.ts +16 -1
- package/lib/routes/nginx/nginx-route.context.js +136 -1
- package/lib/routes/nginx/nginx-server.routes.js +5 -5
- package/lib/routes/node-runtime.routes.d.ts +2 -0
- package/lib/routes/node-runtime.routes.js +69 -0
- package/lib/routes/project.routes.js +117 -13
- package/lib/routes/sprite/sprite-browse.routes.d.ts +2 -0
- package/lib/routes/sprite/sprite-browse.routes.js +137 -0
- package/lib/routes/sprite/sprite-quick.utils.d.ts +19 -0
- package/lib/routes/sprite/sprite-quick.utils.js +247 -0
- package/lib/routes/sprite/sprite.routes.d.ts +2 -0
- package/lib/routes/sprite/sprite.routes.js +212 -0
- package/lib/routes/sprite-browse.routes.js +17 -11
- package/lib/routes/sprite.routes.d.ts +1 -1
- package/lib/routes/sprite.routes.js +68 -11
- package/lib/routes/svn.routes.js +48 -14
- package/lib/routes/task.routes.js +99 -7
- package/package.json +7 -7
- package/www/3rdpartylicenses.txt +5 -5
- package/www/browser/{chunk-OZCK4XVV.js → chunk-2VJVGBXG.js} +1 -1
- package/www/browser/{chunk-FL6GDGHW.js → chunk-3ODVU46S.js} +1 -1
- package/www/browser/chunk-442QFABJ.js +1 -0
- package/www/browser/{chunk-WD2EKZQC.js → chunk-6J6G7JEP.js} +1 -1
- package/www/browser/{chunk-7U44RF5F.js → chunk-6UFDNETG.js} +1 -1
- package/www/browser/{chunk-75W3GVSO.js → chunk-7AKVG375.js} +1 -1
- package/www/browser/chunk-7GLWEFTM.js +1 -0
- package/www/browser/{chunk-DIJPUYIA.js → chunk-7QR6RHLA.js} +1 -1
- package/www/browser/{chunk-HJTXXSMC.js → chunk-CO3CQHKV.js} +1 -1
- package/www/browser/{chunk-3XNNQFWR.js → chunk-CPJTSA6E.js} +1 -1
- package/www/browser/chunk-DENFXXOY.js +1 -0
- package/www/browser/{chunk-HDNG236Q.js → chunk-HC5KLPHD.js} +1 -1
- package/www/browser/chunk-HJAP6WBI.js +1 -0
- package/www/browser/{chunk-N2PELLMM.js → chunk-JM6DCZP6.js} +7 -7
- package/www/browser/chunk-K6C5ZIV2.js +20 -0
- package/www/browser/chunk-M6NZ6C2R.js +2 -0
- package/www/browser/{chunk-RGOYDY7H.js → chunk-MBPB43C6.js} +1 -1
- package/www/browser/chunk-MPLGMTLT.js +3 -0
- package/www/browser/chunk-NNOWADVM.js +1 -0
- package/www/browser/{chunk-M4QRBV3K.js → chunk-NREWZQVN.js} +1 -1
- package/www/browser/{chunk-6YYNHZ2A.js → chunk-OUGN4APK.js} +1 -1
- package/www/browser/chunk-PB2LGZNW.js +1 -0
- package/www/browser/chunk-PDI3HSSH.js +4 -0
- package/www/browser/chunk-PUG3VNTI.js +3 -0
- package/www/browser/{chunk-QJP5F735.js → chunk-PY3AUTHC.js} +1 -1
- package/www/browser/{chunk-3M56F2S2.js → chunk-R4HSZU2J.js} +1 -1
- package/www/browser/{chunk-DE6E23ET.js → chunk-RKK4I2RT.js} +1 -1
- package/www/browser/chunk-RMIYLAEM.js +1 -0
- package/www/browser/chunk-RZA3IFQV.js +2 -0
- package/www/browser/{chunk-K7PESFPY.js → chunk-SD2HFD54.js} +1 -1
- package/www/browser/{chunk-BTQIUVTQ.js → chunk-SEJGGBE2.js} +1 -1
- package/www/browser/chunk-SSCUT2GF.js +1 -0
- package/www/browser/chunk-TCBOC5FF.js +1 -0
- package/www/browser/{chunk-AZ6SIMYH.js → chunk-TS5ZQYYY.js} +1 -1
- package/www/browser/chunk-TVJHI463.js +1 -0
- package/www/browser/{chunk-YNW4HEJO.js → chunk-TXAXE73U.js} +17 -17
- package/www/browser/{chunk-4X42HB6N.js → chunk-U2YWR3HF.js} +1 -1
- package/www/browser/{chunk-D2ODDESN.js → chunk-U3EUR236.js} +1 -1
- package/www/browser/chunk-UKCMUTYL.js +1 -0
- package/www/browser/{chunk-DLGJD6YU.js → chunk-UPOORT3S.js} +1 -1
- package/www/browser/chunk-VW3S7C2Z.js +1 -0
- package/www/browser/chunk-VZYJ3MSW.js +15 -0
- package/www/browser/{chunk-AELTP6YN.js → chunk-WCHN62X6.js} +1 -1
- package/www/browser/chunk-WWIPELAV.js +1 -0
- package/www/browser/{chunk-B3C35ET3.js → chunk-WYNERG74.js} +1 -1
- package/www/browser/{chunk-ZTDLWBW5.js → chunk-XJDJL3TQ.js} +1 -1
- package/www/browser/{chunk-EEDA5U4V.js → chunk-YV6QPLF5.js} +1 -1
- package/www/browser/{chunk-ONXBYGIG.js → chunk-YVRGRFK2.js} +1 -1
- package/www/browser/index.html +1 -1
- package/www/browser/main-7GYUOEJY.js +38 -0
- package/lib/plugins/api-client.plugin.d.ts +0 -3
- package/lib/plugins/api-client.plugin.js +0 -55
- package/lib/plugins/nginx.binding.store.d.ts +0 -4
- package/lib/plugins/nginx.binding.store.js +0 -39
- package/lib/plugins/nginx.plugin.d.ts +0 -3
- package/lib/plugins/nginx.plugin.js +0 -23
- package/www/browser/chunk-2L7NUOMX.js +0 -2
- package/www/browser/chunk-2NZJ7CN2.js +0 -20
- package/www/browser/chunk-3CM4SKDO.js +0 -15
- package/www/browser/chunk-3OHBKMAA.js +0 -1
- package/www/browser/chunk-4LBSLURA.js +0 -1
- package/www/browser/chunk-5DYX4DUX.js +0 -11
- package/www/browser/chunk-6SYVDN5L.js +0 -1
- package/www/browser/chunk-AMXRL4GR.js +0 -1
- package/www/browser/chunk-AV2ZODEH.js +0 -1
- package/www/browser/chunk-CN5J4WNO.js +0 -1
- package/www/browser/chunk-FK6Z4HLL.js +0 -1
- package/www/browser/chunk-FXCG34QS.js +0 -1
- package/www/browser/chunk-H5HGMOE6.js +0 -1
- package/www/browser/chunk-HB3HECPD.js +0 -1
- package/www/browser/chunk-HUMCWAKJ.js +0 -3
- package/www/browser/chunk-IKB3EQCP.js +0 -2
- package/www/browser/chunk-OSBDR36P.js +0 -1
- package/www/browser/chunk-XLFHB7RS.js +0 -3
- package/www/browser/main-N64WJCHX.js +0 -34
|
@@ -2,64 +2,88 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = configRoutes;
|
|
4
4
|
const errors_1 = require("@yinuo-ngm/errors");
|
|
5
|
+
const config_1 = require("@yinuo-ngm/config");
|
|
5
6
|
const editor_1 = require("../common/editor");
|
|
7
|
+
const PATCH_OPS = new Set(["set", "remove", "append", "merge"]);
|
|
8
|
+
function hasOwn(obj, key) {
|
|
9
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
10
|
+
}
|
|
11
|
+
function isPatchValid(patch) {
|
|
12
|
+
if (typeof patch !== "object" || patch === null || Array.isArray(patch)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
const candidate = patch;
|
|
16
|
+
if (typeof candidate.op !== "string" || !PATCH_OPS.has(candidate.op)) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
if (typeof candidate.path !== "string") {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if ((candidate.op === "set" || candidate.op === "append" || candidate.op === "merge") &&
|
|
23
|
+
!hasOwn(candidate, "value")) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
function ensureWriteBody(body) {
|
|
29
|
+
if (!body.type || !body.filePath || !Array.isArray(body.patches)) {
|
|
30
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "missing body.type/body.filePath/body.patches");
|
|
31
|
+
}
|
|
32
|
+
if (!body.patches.every(isPatchValid)) {
|
|
33
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "invalid body.patches[] (require op/path/value)");
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
type: body.type,
|
|
37
|
+
filePath: body.filePath,
|
|
38
|
+
patches: body.patches
|
|
39
|
+
};
|
|
40
|
+
}
|
|
6
41
|
async function configRoutes(fastify) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return
|
|
42
|
+
const config = fastify.core.config;
|
|
43
|
+
fastify.get("/providers", async () => {
|
|
44
|
+
return config.listProviders();
|
|
10
45
|
});
|
|
11
|
-
fastify.get("/
|
|
12
|
-
const
|
|
13
|
-
return
|
|
46
|
+
fastify.get("/detect/:projectId", async (req) => {
|
|
47
|
+
const project = await fastify.core.project.get(req.params.projectId);
|
|
48
|
+
return config.detect(project.root);
|
|
14
49
|
});
|
|
15
|
-
fastify.
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
return await fastify.core.config.writeDoc(projectId, docId, next);
|
|
50
|
+
fastify.get("/doc/:projectId/:type", async (req) => {
|
|
51
|
+
const project = await fastify.core.project.get(req.params.projectId);
|
|
52
|
+
return config.read({
|
|
53
|
+
projectRoot: project.root,
|
|
54
|
+
type: req.params.type,
|
|
55
|
+
filePath: req.query.filePath
|
|
56
|
+
});
|
|
23
57
|
});
|
|
24
|
-
fastify.post("/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
58
|
+
fastify.post("/preview/:projectId", async (req) => {
|
|
59
|
+
const body = ensureWriteBody(req.body ?? {});
|
|
60
|
+
const project = await fastify.core.project.get(req.params.projectId);
|
|
61
|
+
return config.preview({
|
|
62
|
+
projectRoot: project.root,
|
|
63
|
+
type: body.type,
|
|
64
|
+
filePath: body.filePath,
|
|
65
|
+
patches: body.patches
|
|
66
|
+
});
|
|
34
67
|
});
|
|
35
|
-
fastify.
|
|
36
|
-
const
|
|
37
|
-
|
|
68
|
+
fastify.post("/write/:projectId", async (req) => {
|
|
69
|
+
const body = ensureWriteBody(req.body ?? {});
|
|
70
|
+
const project = await fastify.core.project.get(req.params.projectId);
|
|
71
|
+
return config.write({
|
|
72
|
+
projectRoot: project.root,
|
|
73
|
+
type: body.type,
|
|
74
|
+
filePath: body.filePath,
|
|
75
|
+
patches: body.patches
|
|
76
|
+
});
|
|
38
77
|
});
|
|
39
|
-
fastify.post("/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const vm = body?.vm;
|
|
43
|
-
if (vm === undefined) {
|
|
44
|
-
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "missing body.vm");
|
|
78
|
+
fastify.post("/openInEditor/:projectId", async (req) => {
|
|
79
|
+
if (!req.body?.filePath) {
|
|
80
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "missing body.filePath");
|
|
45
81
|
}
|
|
46
|
-
await fastify.core.
|
|
82
|
+
const project = await fastify.core.project.get(req.params.projectId);
|
|
83
|
+
const absPath = (0, config_1.resolveProjectFile)(project.root, req.body.filePath);
|
|
84
|
+
await (0, editor_1.openFolder)(absPath, { editor: "code" });
|
|
47
85
|
return {
|
|
48
|
-
|
|
49
|
-
domainId,
|
|
86
|
+
filePath: absPath
|
|
50
87
|
};
|
|
51
88
|
});
|
|
52
|
-
fastify.get("/getDomainSchema/:projectId/:domainId", async (req) => {
|
|
53
|
-
const { projectId, domainId } = req.params;
|
|
54
|
-
return await fastify.core.config.getDomainSchemaDoc(projectId, domainId);
|
|
55
|
-
});
|
|
56
|
-
fastify.post("/diffSchema/:projectId/:domainId", async (req) => {
|
|
57
|
-
const { projectId, domainId } = req.params;
|
|
58
|
-
const body = req.body;
|
|
59
|
-
const vm = body?.vm;
|
|
60
|
-
if (vm === undefined) {
|
|
61
|
-
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "missing body.vm");
|
|
62
|
-
}
|
|
63
|
-
return await fastify.core.config.diffDomainSchema(projectId, domainId, vm);
|
|
64
|
-
});
|
|
65
89
|
}
|
package/lib/routes/deps.route.js
CHANGED
|
@@ -1,25 +1,67 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = depsRoutes;
|
|
4
|
+
const errors_1 = require("@yinuo-ngm/errors");
|
|
5
|
+
function toDepItemDto(item) {
|
|
6
|
+
return {
|
|
7
|
+
name: item.name,
|
|
8
|
+
current: item.current,
|
|
9
|
+
required: item.required,
|
|
10
|
+
latest: item.latest,
|
|
11
|
+
installed: item.installed,
|
|
12
|
+
hasUpdate: item.hasUpdate,
|
|
13
|
+
group: item.group,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function toProjectDepsMetaDto(meta) {
|
|
17
|
+
return {
|
|
18
|
+
packageManager: meta.packageManager,
|
|
19
|
+
registryOnline: meta.registryOnline,
|
|
20
|
+
voltaConfig: meta.voltaConfig,
|
|
21
|
+
enginesNode: meta.enginesNode,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function toProjectDepsResultDto(result) {
|
|
25
|
+
return {
|
|
26
|
+
dependencies: result.dependencies.map(toDepItemDto),
|
|
27
|
+
devDependencies: result.devDependencies.map(toDepItemDto),
|
|
28
|
+
meta: toProjectDepsMetaDto(result.meta),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
4
31
|
async function depsRoutes(fastify) {
|
|
32
|
+
const deps = fastify.core.deps;
|
|
5
33
|
fastify.get("/list/:projectId", async (req) => {
|
|
6
34
|
const { projectId } = req.params;
|
|
7
|
-
const
|
|
8
|
-
return
|
|
35
|
+
const result = await deps.list(projectId);
|
|
36
|
+
return toProjectDepsResultDto(result);
|
|
9
37
|
});
|
|
10
38
|
fastify.post("/install/:projectId", async (req) => {
|
|
11
39
|
const { projectId } = req.params;
|
|
12
40
|
const body = req.body;
|
|
13
|
-
|
|
41
|
+
if (!body.name || !body.group || !body.target) {
|
|
42
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "missing required fields: name, group, target");
|
|
43
|
+
}
|
|
44
|
+
await deps.install(projectId, {
|
|
45
|
+
name: body.name,
|
|
46
|
+
group: body.group,
|
|
47
|
+
target: body.target,
|
|
48
|
+
version: body.version,
|
|
49
|
+
});
|
|
14
50
|
return { ok: true };
|
|
15
51
|
});
|
|
16
52
|
fastify.post("/uninstall/:projectId", async (req) => {
|
|
17
53
|
const { projectId } = req.params;
|
|
18
54
|
const body = req.body;
|
|
19
|
-
|
|
55
|
+
if (!body.name || !body.group) {
|
|
56
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "missing required fields: name, group");
|
|
57
|
+
}
|
|
58
|
+
await deps.uninstall(projectId, {
|
|
59
|
+
name: body.name,
|
|
60
|
+
group: body.group,
|
|
61
|
+
});
|
|
20
62
|
return { ok: true };
|
|
21
63
|
});
|
|
22
|
-
fastify.post("/devtools/install/:projectId", async (
|
|
64
|
+
fastify.post("/devtools/install/:projectId", async () => {
|
|
23
65
|
return { ok: true };
|
|
24
66
|
});
|
|
25
67
|
}
|
package/lib/routes/index.js
CHANGED
|
@@ -10,15 +10,16 @@ const deps_route_1 = __importDefault(require("./deps.route"));
|
|
|
10
10
|
const fs_routes_1 = __importDefault(require("./fs.routes"));
|
|
11
11
|
const project_routes_1 = __importDefault(require("./project.routes"));
|
|
12
12
|
const rss_routes_1 = __importDefault(require("./rss.routes"));
|
|
13
|
-
const sprite_routes_1 = require("./sprite.routes");
|
|
13
|
+
const sprite_routes_1 = require("./sprite/sprite.routes");
|
|
14
14
|
const system_routes_1 = __importDefault(require("./system.routes"));
|
|
15
15
|
const task_routes_1 = __importDefault(require("./task.routes"));
|
|
16
16
|
const api_client_1 = require("./api-client");
|
|
17
17
|
const nginx_routes_1 = require("./nginx.routes");
|
|
18
18
|
const svn_routes_1 = __importDefault(require("./svn.routes"));
|
|
19
|
-
const sprite_browse_routes_1 = __importDefault(require("./sprite-browse.routes"));
|
|
19
|
+
const sprite_browse_routes_1 = __importDefault(require("./sprite/sprite-browse.routes"));
|
|
20
20
|
const static_files_routes_1 = __importDefault(require("./static-files.routes"));
|
|
21
21
|
const hub_routes_1 = __importDefault(require("./hub.routes"));
|
|
22
|
+
const node_runtime_routes_1 = __importDefault(require("./node-runtime.routes"));
|
|
22
23
|
const node_version_routes_1 = __importDefault(require("./node-version.routes"));
|
|
23
24
|
async function routes(fastify) {
|
|
24
25
|
await fastify.register(system_routes_1.default);
|
|
@@ -29,8 +30,8 @@ async function routes(fastify) {
|
|
|
29
30
|
await fastify.register(config_routes_1.default, { prefix: '/api/config' });
|
|
30
31
|
await fastify.register(dashboard_routes_1.default, { prefix: '/api/dashboard' });
|
|
31
32
|
await fastify.register(rss_routes_1.default, { prefix: '/api/rss' });
|
|
32
|
-
await fastify.register(sprite_routes_1.spriteRoutes, { prefix: '/api/sprite' });
|
|
33
33
|
await fastify.register(svn_routes_1.default, { prefix: '/api/svn' });
|
|
34
|
+
await fastify.register(sprite_routes_1.spriteRoutes, { prefix: '/api/sprite' });
|
|
34
35
|
await fastify.register(sprite_browse_routes_1.default, { prefix: '/api/sprite/browse' });
|
|
35
36
|
await fastify.register(static_files_routes_1.default, { prefix: '/api/static' });
|
|
36
37
|
await fastify.register(hub_routes_1.default, { prefix: '/api/hub' });
|
|
@@ -42,4 +43,5 @@ async function routes(fastify) {
|
|
|
42
43
|
await fastify.register(api_client_1.apiClientHubTokenRoutes, { prefix: '/api/client/hub-token' });
|
|
43
44
|
await fastify.register(nginx_routes_1.nginxRoutes, { prefix: '/api/nginx' });
|
|
44
45
|
await fastify.register(node_version_routes_1.default, { prefix: '/api/node-version' });
|
|
46
|
+
await fastify.register(node_runtime_routes_1.default, { prefix: '/api/node-runtimes' });
|
|
45
47
|
}
|
|
@@ -9,7 +9,7 @@ function registerNginxConfigRoutes(context) {
|
|
|
9
9
|
const config = await nginx.config.readMainConfig();
|
|
10
10
|
return reply.send({
|
|
11
11
|
success: true,
|
|
12
|
-
config,
|
|
12
|
+
config: (0, nginx_route_context_1.toNginxConfigDto)(config),
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
catch (error) {
|
|
@@ -31,7 +31,7 @@ function registerNginxConfigRoutes(context) {
|
|
|
31
31
|
fastify.post('/config/validate', async (request, reply) => {
|
|
32
32
|
const { content } = request.body;
|
|
33
33
|
const result = await nginx.config.validateConfig(content);
|
|
34
|
-
return reply.send(result);
|
|
34
|
+
return reply.send((0, nginx_route_context_1.toNginxConfigValidationDto)(result));
|
|
35
35
|
});
|
|
36
36
|
fastify.get('/config/files', async (_request, reply) => {
|
|
37
37
|
try {
|
|
@@ -53,7 +53,7 @@ function registerNginxConfigRoutes(context) {
|
|
|
53
53
|
if (isMainConfig) {
|
|
54
54
|
return reply.send({
|
|
55
55
|
success: true,
|
|
56
|
-
config: mainConfig,
|
|
56
|
+
config: (0, nginx_route_context_1.toNginxConfigDto)(mainConfig),
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
59
|
const content = await nginx.config.readConfigFile(filePath);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.registerNginxLifecycleRoutes = registerNginxLifecycleRoutes;
|
|
4
|
-
const
|
|
4
|
+
const core_1 = require("@yinuo-ngm/core");
|
|
5
|
+
const env_1 = require("../../env");
|
|
5
6
|
const nginx_route_context_1 = require("./nginx-route.context");
|
|
6
7
|
function registerNginxLifecycleRoutes(context) {
|
|
7
8
|
const { fastify, nginx } = context;
|
|
@@ -9,8 +10,8 @@ function registerNginxLifecycleRoutes(context) {
|
|
|
9
10
|
const instance = nginx.service.getInstance();
|
|
10
11
|
const status = await nginx.service.getStatus();
|
|
11
12
|
return reply.send({
|
|
12
|
-
instance,
|
|
13
|
-
status,
|
|
13
|
+
instance: (0, nginx_route_context_1.toNginxInstanceDto)(instance),
|
|
14
|
+
status: (0, nginx_route_context_1.toNginxStatusDto)(status),
|
|
14
15
|
});
|
|
15
16
|
});
|
|
16
17
|
fastify.get('/stats', async (_request, reply) => {
|
|
@@ -18,11 +19,11 @@ function registerNginxLifecycleRoutes(context) {
|
|
|
18
19
|
const instance = nginx.service.getInstance();
|
|
19
20
|
const status = await nginx.service.getStatus();
|
|
20
21
|
const servers = await nginx.server.getAllServers();
|
|
21
|
-
const enabled = servers.filter(item => item.enabled).length;
|
|
22
|
+
const enabled = servers.filter((item) => item.enabled).length;
|
|
22
23
|
return reply.send({
|
|
23
24
|
success: true,
|
|
24
|
-
instance,
|
|
25
|
-
status,
|
|
25
|
+
instance: (0, nginx_route_context_1.toNginxInstanceDto)(instance),
|
|
26
|
+
status: (0, nginx_route_context_1.toNginxStatusDto)(status),
|
|
26
27
|
serverSummary: {
|
|
27
28
|
total: servers.length,
|
|
28
29
|
enabled,
|
|
@@ -39,14 +40,14 @@ function registerNginxLifecycleRoutes(context) {
|
|
|
39
40
|
try {
|
|
40
41
|
const instance = await nginx.service.bind(path);
|
|
41
42
|
try {
|
|
42
|
-
await (0,
|
|
43
|
+
await (0, core_1.savePersistedNginxPath)(env_1.env.dataDir, instance.path);
|
|
43
44
|
}
|
|
44
45
|
catch (persistError) {
|
|
45
46
|
fastify.log.warn(`[nginx] binding persisted failed: ${String(persistError)}`);
|
|
46
47
|
}
|
|
47
48
|
return reply.send({
|
|
48
49
|
success: true,
|
|
49
|
-
instance,
|
|
50
|
+
instance: (0, nginx_route_context_1.toNginxInstanceDto)(instance) ?? undefined,
|
|
50
51
|
});
|
|
51
52
|
}
|
|
52
53
|
catch (error) {
|
|
@@ -56,7 +57,7 @@ function registerNginxLifecycleRoutes(context) {
|
|
|
56
57
|
fastify.post('/unbind', async (_request, reply) => {
|
|
57
58
|
nginx.service.unbind();
|
|
58
59
|
try {
|
|
59
|
-
await (0,
|
|
60
|
+
await (0, core_1.clearPersistedNginxPath)(env_1.env.dataDir);
|
|
60
61
|
}
|
|
61
62
|
catch (error) {
|
|
62
63
|
fastify.log.warn(`[nginx] clear persisted binding failed: ${String(error)}`);
|
|
@@ -67,7 +68,7 @@ function registerNginxLifecycleRoutes(context) {
|
|
|
67
68
|
});
|
|
68
69
|
fastify.get('/local-ip', async (_request, reply) => {
|
|
69
70
|
const result = await nginx.service.getLocalIp();
|
|
70
|
-
return reply.send(result);
|
|
71
|
+
return reply.send((0, nginx_route_context_1.toNginxCommandResultDto)(result));
|
|
71
72
|
});
|
|
72
73
|
fastify.post('/start', async (_request, reply) => {
|
|
73
74
|
const result = await nginx.service.start();
|
|
@@ -77,7 +78,7 @@ function registerNginxLifecycleRoutes(context) {
|
|
|
77
78
|
else {
|
|
78
79
|
fastify.core.sysLog.error({ scope: 'system', source: 'server', text: `[Nginx] 启动失败: ${result.error || '未知错误'}` });
|
|
79
80
|
}
|
|
80
|
-
return reply.send(result);
|
|
81
|
+
return reply.send((0, nginx_route_context_1.toNginxCommandResultDto)(result));
|
|
81
82
|
});
|
|
82
83
|
fastify.post('/stop', async (_request, reply) => {
|
|
83
84
|
const result = await nginx.service.stop();
|
|
@@ -87,7 +88,7 @@ function registerNginxLifecycleRoutes(context) {
|
|
|
87
88
|
else {
|
|
88
89
|
fastify.core.sysLog.error({ scope: 'system', source: 'server', text: `[Nginx] 停止失败: ${result.error || '未知错误'}` });
|
|
89
90
|
}
|
|
90
|
-
return reply.send(result);
|
|
91
|
+
return reply.send((0, nginx_route_context_1.toNginxCommandResultDto)(result));
|
|
91
92
|
});
|
|
92
93
|
fastify.post('/reload', async (_request, reply) => {
|
|
93
94
|
const result = await nginx.service.reload();
|
|
@@ -107,6 +108,6 @@ function registerNginxLifecycleRoutes(context) {
|
|
|
107
108
|
else {
|
|
108
109
|
fastify.core.sysLog.error({ scope: 'system', source: 'server', text: `[Nginx] 配置检测失败: ${(result.errors || []).join(', ')}` });
|
|
109
110
|
}
|
|
110
|
-
return reply.send(result);
|
|
111
|
+
return reply.send((0, nginx_route_context_1.toNginxConfigValidationDto)(result));
|
|
111
112
|
});
|
|
112
113
|
}
|
|
@@ -9,7 +9,7 @@ function registerNginxModuleRoutes(context) {
|
|
|
9
9
|
const upstreams = await nginx.module.getUpstreams();
|
|
10
10
|
return reply.send({
|
|
11
11
|
success: true,
|
|
12
|
-
upstreams,
|
|
12
|
+
upstreams: upstreams.map(nginx_route_context_1.toNginxUpstreamDto),
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
catch (error) {
|
|
@@ -32,7 +32,7 @@ function registerNginxModuleRoutes(context) {
|
|
|
32
32
|
const certificates = await nginx.module.getSslCertificates();
|
|
33
33
|
return reply.send({
|
|
34
34
|
success: true,
|
|
35
|
-
certificates,
|
|
35
|
+
certificates: certificates.map(nginx_route_context_1.toNginxSslCertificateDto),
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
catch (error) {
|
|
@@ -55,7 +55,7 @@ function registerNginxModuleRoutes(context) {
|
|
|
55
55
|
const traffic = await nginx.module.getTrafficConfig();
|
|
56
56
|
return reply.send({
|
|
57
57
|
success: true,
|
|
58
|
-
traffic,
|
|
58
|
+
traffic: (0, nginx_route_context_1.toNginxTrafficConfigDto)(traffic),
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
catch (error) {
|
|
@@ -78,7 +78,7 @@ function registerNginxModuleRoutes(context) {
|
|
|
78
78
|
const performance = await nginx.module.getPerformanceConfig();
|
|
79
79
|
return reply.send({
|
|
80
80
|
success: true,
|
|
81
|
-
performance,
|
|
81
|
+
performance: (0, nginx_route_context_1.toNginxPerformanceConfigDto)(performance),
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
84
|
catch (error) {
|
|
@@ -101,7 +101,7 @@ function registerNginxModuleRoutes(context) {
|
|
|
101
101
|
const settings = await nginx.module.getModuleSettings();
|
|
102
102
|
return reply.send({
|
|
103
103
|
success: true,
|
|
104
|
-
settings,
|
|
104
|
+
settings: (0, nginx_route_context_1.toNginxModuleSettingsDto)(settings),
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
catch (error) {
|
|
@@ -113,7 +113,7 @@ function registerNginxModuleRoutes(context) {
|
|
|
113
113
|
const settings = await nginx.module.saveModuleSettings(request.body || {});
|
|
114
114
|
return reply.send({
|
|
115
115
|
success: true,
|
|
116
|
-
settings,
|
|
116
|
+
settings: (0, nginx_route_context_1.toNginxModuleSettingsDto)(settings),
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
119
|
catch (error) {
|
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import type { FastifyInstance, FastifyReply } from 'fastify';
|
|
2
|
+
import type { NginxApp } from '@yinuo-ngm/nginx';
|
|
3
|
+
import type { NginxCommandResultDto, NginxConfigDto, NginxConfigValidationDto, NginxInstanceDto, NginxLocationDto, NginxModuleSettingsDto, NginxPerformanceConfigDto, NginxServerDto, NginxSslCertificateDto, NginxStatusDto, NginxTrafficConfigDto, NginxUpstreamDto } from '@yinuo-ngm/protocol';
|
|
4
|
+
import type { NginxCommandResult, NginxConfig, NginxConfigValidation, NginxInstance, NginxLocation, NginxModuleSettings, NginxPerformanceConfig, NginxServer, NginxSslCertificate, NginxStatus, NginxTrafficConfig, NginxUpstream } from '@yinuo-ngm/nginx';
|
|
2
5
|
export interface NginxRouteContext {
|
|
3
6
|
fastify: FastifyInstance;
|
|
4
|
-
nginx:
|
|
7
|
+
nginx: NginxApp;
|
|
5
8
|
normalizeFsPath: (filePath: string) => string;
|
|
6
9
|
ensureManageableConfigFile: (rawPath?: string) => Promise<string>;
|
|
7
10
|
}
|
|
8
11
|
export declare function createNginxRouteContext(fastify: FastifyInstance): NginxRouteContext;
|
|
9
12
|
export declare function sendBadRequest(reply: FastifyReply, error: unknown): void;
|
|
13
|
+
export declare function toNginxInstanceDto(instance: NginxInstance | null | undefined): NginxInstanceDto | null;
|
|
14
|
+
export declare function toNginxStatusDto(status: NginxStatus): NginxStatusDto;
|
|
15
|
+
export declare function toNginxConfigDto(config: NginxConfig): NginxConfigDto;
|
|
16
|
+
export declare function toNginxLocationDto(location: NginxLocation): NginxLocationDto;
|
|
17
|
+
export declare function toNginxServerDto(server: NginxServer): NginxServerDto;
|
|
18
|
+
export declare function toNginxCommandResultDto(result: NginxCommandResult): NginxCommandResultDto;
|
|
19
|
+
export declare function toNginxConfigValidationDto(result: NginxConfigValidation): NginxConfigValidationDto;
|
|
20
|
+
export declare function toNginxUpstreamDto(upstream: NginxUpstream): NginxUpstreamDto;
|
|
21
|
+
export declare function toNginxSslCertificateDto(certificate: NginxSslCertificate): NginxSslCertificateDto;
|
|
22
|
+
export declare function toNginxTrafficConfigDto(config: NginxTrafficConfig): NginxTrafficConfigDto;
|
|
23
|
+
export declare function toNginxPerformanceConfigDto(config: NginxPerformanceConfig): NginxPerformanceConfigDto;
|
|
24
|
+
export declare function toNginxModuleSettingsDto(settings: NginxModuleSettings): NginxModuleSettingsDto;
|
|
@@ -2,11 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createNginxRouteContext = createNginxRouteContext;
|
|
4
4
|
exports.sendBadRequest = sendBadRequest;
|
|
5
|
+
exports.toNginxInstanceDto = toNginxInstanceDto;
|
|
6
|
+
exports.toNginxStatusDto = toNginxStatusDto;
|
|
7
|
+
exports.toNginxConfigDto = toNginxConfigDto;
|
|
8
|
+
exports.toNginxLocationDto = toNginxLocationDto;
|
|
9
|
+
exports.toNginxServerDto = toNginxServerDto;
|
|
10
|
+
exports.toNginxCommandResultDto = toNginxCommandResultDto;
|
|
11
|
+
exports.toNginxConfigValidationDto = toNginxConfigValidationDto;
|
|
12
|
+
exports.toNginxUpstreamDto = toNginxUpstreamDto;
|
|
13
|
+
exports.toNginxSslCertificateDto = toNginxSslCertificateDto;
|
|
14
|
+
exports.toNginxTrafficConfigDto = toNginxTrafficConfigDto;
|
|
15
|
+
exports.toNginxPerformanceConfigDto = toNginxPerformanceConfigDto;
|
|
16
|
+
exports.toNginxModuleSettingsDto = toNginxModuleSettingsDto;
|
|
5
17
|
const promises_1 = require("fs/promises");
|
|
6
18
|
const path_1 = require("path");
|
|
7
19
|
const errors_1 = require("@yinuo-ngm/errors");
|
|
8
20
|
function createNginxRouteContext(fastify) {
|
|
9
|
-
const nginx = fastify.nginx;
|
|
21
|
+
const nginx = fastify.core.nginx;
|
|
10
22
|
const normalizeFsPath = (filePath) => (0, path_1.resolve)(filePath).replace(/\\/g, '/').toLowerCase();
|
|
11
23
|
const ensureManageableConfigFile = async (rawPath) => {
|
|
12
24
|
const filePath = rawPath?.trim();
|
|
@@ -50,3 +62,126 @@ function sendBadRequest(reply, error) {
|
|
|
50
62
|
method: reply.request?.method,
|
|
51
63
|
});
|
|
52
64
|
}
|
|
65
|
+
function toNginxInstanceDto(instance) {
|
|
66
|
+
if (!instance)
|
|
67
|
+
return null;
|
|
68
|
+
return {
|
|
69
|
+
path: instance.path,
|
|
70
|
+
version: instance.version,
|
|
71
|
+
configPath: instance.configPath,
|
|
72
|
+
prefixPath: instance.prefixPath,
|
|
73
|
+
isBound: instance.isBound,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function toNginxStatusDto(status) {
|
|
77
|
+
return {
|
|
78
|
+
isRunning: status.isRunning,
|
|
79
|
+
pid: status.pid,
|
|
80
|
+
uptime: status.uptime,
|
|
81
|
+
activeConnections: status.activeConnections,
|
|
82
|
+
workerProcesses: status.workerProcesses,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function toNginxConfigDto(config) {
|
|
86
|
+
return {
|
|
87
|
+
mainConfigPath: config.mainConfigPath,
|
|
88
|
+
content: config.content,
|
|
89
|
+
isWritable: config.isWritable,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function toNginxLocationDto(location) {
|
|
93
|
+
return {
|
|
94
|
+
path: location.path,
|
|
95
|
+
proxyPass: location.proxyPass,
|
|
96
|
+
root: location.root,
|
|
97
|
+
index: location.index,
|
|
98
|
+
tryFiles: location.tryFiles,
|
|
99
|
+
rawConfig: location.rawConfig,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function toNginxServerDto(server) {
|
|
103
|
+
return {
|
|
104
|
+
id: server.id,
|
|
105
|
+
name: server.name,
|
|
106
|
+
listen: server.listen,
|
|
107
|
+
domains: server.domains,
|
|
108
|
+
root: server.root,
|
|
109
|
+
index: server.index,
|
|
110
|
+
locations: (server.locations ?? []).map(toNginxLocationDto),
|
|
111
|
+
ssl: server.ssl,
|
|
112
|
+
sslCert: server.sslCert,
|
|
113
|
+
sslKey: server.sslKey,
|
|
114
|
+
enabled: server.enabled,
|
|
115
|
+
extraConfig: server.extraConfig,
|
|
116
|
+
configText: server.configText,
|
|
117
|
+
filePath: server.filePath,
|
|
118
|
+
createdAt: server.createdAt,
|
|
119
|
+
updatedAt: server.updatedAt,
|
|
120
|
+
createdBy: server.createdBy,
|
|
121
|
+
runtimeStatus: server.runtimeStatus,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function toNginxCommandResultDto(result) {
|
|
125
|
+
return {
|
|
126
|
+
success: result.success,
|
|
127
|
+
output: result.output,
|
|
128
|
+
error: result.error,
|
|
129
|
+
exitCode: result.exitCode,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function toNginxConfigValidationDto(result) {
|
|
133
|
+
return {
|
|
134
|
+
valid: result.valid,
|
|
135
|
+
errors: result.errors,
|
|
136
|
+
warnings: result.warnings,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function toNginxUpstreamDto(upstream) {
|
|
140
|
+
return {
|
|
141
|
+
id: upstream.id,
|
|
142
|
+
name: upstream.name,
|
|
143
|
+
strategy: upstream.strategy,
|
|
144
|
+
nodes: upstream.nodes,
|
|
145
|
+
sourceFile: upstream.sourceFile,
|
|
146
|
+
managed: upstream.managed,
|
|
147
|
+
readonly: upstream.readonly,
|
|
148
|
+
health: upstream.health,
|
|
149
|
+
healthy: upstream.healthy,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function toNginxSslCertificateDto(certificate) {
|
|
153
|
+
return {
|
|
154
|
+
id: certificate.id,
|
|
155
|
+
domain: certificate.domain,
|
|
156
|
+
certPath: certificate.certPath,
|
|
157
|
+
keyPath: certificate.keyPath,
|
|
158
|
+
expireAt: certificate.expireAt,
|
|
159
|
+
status: certificate.status,
|
|
160
|
+
autoRenew: certificate.autoRenew,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function toNginxTrafficConfigDto(config) {
|
|
164
|
+
return {
|
|
165
|
+
rateLimitEnabled: config.rateLimitEnabled,
|
|
166
|
+
rateLimit: config.rateLimit,
|
|
167
|
+
connLimitEnabled: config.connLimitEnabled,
|
|
168
|
+
connLimit: config.connLimit,
|
|
169
|
+
blacklistIps: config.blacklistIps,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function toNginxPerformanceConfigDto(config) {
|
|
173
|
+
return {
|
|
174
|
+
gzipEnabled: config.gzipEnabled,
|
|
175
|
+
gzipTypes: config.gzipTypes,
|
|
176
|
+
keepaliveTimeout: config.keepaliveTimeout,
|
|
177
|
+
workerProcesses: config.workerProcesses,
|
|
178
|
+
sendfile: config.sendfile,
|
|
179
|
+
tcpNopush: config.tcpNopush,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function toNginxModuleSettingsDto(settings) {
|
|
183
|
+
return {
|
|
184
|
+
backupRetention: settings.backupRetention,
|
|
185
|
+
configBackupRetention: settings.configBackupRetention,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
@@ -74,7 +74,7 @@ function registerNginxServerRoutes(context) {
|
|
|
74
74
|
}));
|
|
75
75
|
return reply.send({
|
|
76
76
|
success: true,
|
|
77
|
-
servers: enriched,
|
|
77
|
+
servers: enriched.map(nginx_route_context_1.toNginxServerDto),
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
catch (error) {
|
|
@@ -104,7 +104,7 @@ function registerNginxServerRoutes(context) {
|
|
|
104
104
|
};
|
|
105
105
|
return reply.send({
|
|
106
106
|
success: true,
|
|
107
|
-
server: enriched,
|
|
107
|
+
server: (0, nginx_route_context_1.toNginxServerDto)(enriched),
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
110
|
catch (error) {
|
|
@@ -120,7 +120,7 @@ function registerNginxServerRoutes(context) {
|
|
|
120
120
|
const server = await nginx.server.createServer(payload);
|
|
121
121
|
return reply.send({
|
|
122
122
|
success: true,
|
|
123
|
-
server,
|
|
123
|
+
server: (0, nginx_route_context_1.toNginxServerDto)(server),
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
126
|
catch (error) {
|
|
@@ -133,7 +133,7 @@ function registerNginxServerRoutes(context) {
|
|
|
133
133
|
const server = await nginx.server.updateServer(id, request.body);
|
|
134
134
|
return reply.send({
|
|
135
135
|
success: true,
|
|
136
|
-
server,
|
|
136
|
+
server: (0, nginx_route_context_1.toNginxServerDto)(server),
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
139
|
catch (error) {
|
|
@@ -162,7 +162,7 @@ function registerNginxServerRoutes(context) {
|
|
|
162
162
|
const server = await nginx.server.restoreDeletedServer(snapshotId);
|
|
163
163
|
return reply.send({
|
|
164
164
|
success: true,
|
|
165
|
-
server,
|
|
165
|
+
server: (0, nginx_route_context_1.toNginxServerDto)(server),
|
|
166
166
|
});
|
|
167
167
|
}
|
|
168
168
|
catch (error) {
|