@yinuo-ngm/server 1.0.14 → 1.0.16
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 +2 -0
- package/lib/plugins/error-handler.plugin.js +5 -0
- package/lib/plugins/nginx.binding.store.d.ts +4 -0
- package/lib/plugins/nginx.binding.store.js +39 -0
- package/lib/plugins/nginx.plugin.d.ts +3 -0
- package/lib/plugins/nginx.plugin.js +23 -0
- package/lib/plugins/ws/topics/index.d.ts +1 -0
- package/lib/plugins/ws/topics/index.js +1 -0
- package/lib/plugins/ws/topics/nginx.ws.d.ts +7 -0
- package/lib/plugins/ws/topics/nginx.ws.js +59 -0
- package/lib/plugins/ws/ws.plugin.js +3 -0
- package/lib/routes/api-client/hub-cookie-jar.d.ts +3 -0
- package/lib/routes/api-client/hub-cookie-jar.js +54 -0
- package/lib/routes/api-client/hub-token.routes.d.ts +2 -0
- package/lib/routes/api-client/hub-token.routes.js +284 -0
- package/lib/routes/api-client/index.d.ts +1 -0
- package/lib/routes/api-client/index.js +1 -0
- package/lib/routes/api-client/send.routes.js +60 -1
- package/lib/routes/hub.routes.d.ts +2 -0
- package/lib/routes/hub.routes.js +103 -0
- package/lib/routes/index.js +7 -0
- package/lib/routes/nginx/nginx-config.routes.d.ts +2 -0
- package/lib/routes/nginx/nginx-config.routes.js +94 -0
- package/lib/routes/nginx/nginx-lifecycle.routes.d.ts +2 -0
- package/lib/routes/nginx/nginx-lifecycle.routes.js +108 -0
- package/lib/routes/nginx/nginx-log.routes.d.ts +2 -0
- package/lib/routes/nginx/nginx-log.routes.js +47 -0
- package/lib/routes/nginx/nginx-module.routes.d.ts +2 -0
- package/lib/routes/nginx/nginx-module.routes.js +123 -0
- package/lib/routes/nginx/nginx-route.context.d.ts +9 -0
- package/lib/routes/nginx/nginx-route.context.js +36 -0
- package/lib/routes/nginx/nginx-server.routes.d.ts +2 -0
- package/lib/routes/nginx/nginx-server.routes.js +97 -0
- package/lib/routes/nginx.routes.d.ts +2 -0
- package/lib/routes/nginx.routes.js +17 -0
- package/lib/routes/node-version.routes.d.ts +2 -0
- package/lib/routes/node-version.routes.js +56 -0
- package/lib/routes/project.routes.js +5 -0
- package/lib/routes/sprite-browse.routes.js +19 -5
- package/lib/routes/sprite.routes.js +17 -11
- package/lib/routes/static-files.routes.js +16 -0
- package/lib/routes/task.routes.js +7 -0
- package/package.json +5 -4
- package/www/3rdpartylicenses.txt +75 -0
- package/www/browser/assets/vs/_commonjsHelpers-CT9FvmAN.js +1 -0
- package/www/browser/assets/vs/abap-D-t0cyap.js +1 -0
- package/www/browser/assets/vs/apex-CcIm7xu6.js +1 -0
- package/www/browser/assets/vs/assets/css.worker-HnVq6Ewq.js +93 -0
- package/www/browser/assets/vs/assets/editor.worker-Be8ye1pW.js +26 -0
- package/www/browser/assets/vs/assets/html.worker-B51mlPHg.js +470 -0
- package/www/browser/assets/vs/assets/json.worker-DKiEKt88.js +58 -0
- package/www/browser/assets/vs/assets/ts.worker-CMbG-7ft.js +67731 -0
- package/www/browser/assets/vs/azcli-BA0tQDCg.js +1 -0
- package/www/browser/assets/vs/basic-languages/monaco.contribution.js +1 -0
- package/www/browser/assets/vs/bat-C397hTD6.js +1 -0
- package/www/browser/assets/vs/bicep-DF5aW17k.js +2 -0
- package/www/browser/assets/vs/cameligo-plsz8qhj.js +1 -0
- package/www/browser/assets/vs/clojure-Y2auQMzK.js +1 -0
- package/www/browser/assets/vs/coffee-Bu45yuWE.js +1 -0
- package/www/browser/assets/vs/cpp-CkKPQIni.js +1 -0
- package/www/browser/assets/vs/csharp-CX28MZyh.js +1 -0
- package/www/browser/assets/vs/csp-D8uWnyxW.js +1 -0
- package/www/browser/assets/vs/css-CaeNmE3S.js +3 -0
- package/www/browser/assets/vs/cssMode-CjiAH6dQ.js +1 -0
- package/www/browser/assets/vs/cypher-DVThT8BS.js +1 -0
- package/www/browser/assets/vs/dart-CmGfCvrO.js +1 -0
- package/www/browser/assets/vs/dockerfile-CZqqYdch.js +1 -0
- package/www/browser/assets/vs/ecl-30fUercY.js +1 -0
- package/www/browser/assets/vs/editor/editor.main.css +1 -0
- package/www/browser/assets/vs/editor/editor.main.js +5 -0
- package/www/browser/assets/vs/editor.api-CalNCsUg.js +903 -0
- package/www/browser/assets/vs/elixir-xjPaIfzF.js +1 -0
- package/www/browser/assets/vs/flow9-DqtmStfK.js +1 -0
- package/www/browser/assets/vs/freemarker2-Cz_sV6Md.js +3 -0
- package/www/browser/assets/vs/fsharp-BOMdg4U1.js +1 -0
- package/www/browser/assets/vs/go-D_hbi-Jt.js +1 -0
- package/www/browser/assets/vs/graphql-CKUU4kLG.js +1 -0
- package/www/browser/assets/vs/handlebars-OwglfO-1.js +1 -0
- package/www/browser/assets/vs/hcl-DTaboeZW.js +1 -0
- package/www/browser/assets/vs/html-Pa1xEWsY.js +1 -0
- package/www/browser/assets/vs/htmlMode-Bz67EXwp.js +1 -0
- package/www/browser/assets/vs/ini-CsNwO04R.js +1 -0
- package/www/browser/assets/vs/java-CI4ZMsH9.js +1 -0
- package/www/browser/assets/vs/javascript-PczUCGdz.js +1 -0
- package/www/browser/assets/vs/jsonMode-DULH5oaX.js +7 -0
- package/www/browser/assets/vs/julia-BwzEvaQw.js +1 -0
- package/www/browser/assets/vs/kotlin-IUYPiTV8.js +1 -0
- package/www/browser/assets/vs/language/css/monaco.contribution.js +1 -0
- package/www/browser/assets/vs/language/html/monaco.contribution.js +1 -0
- package/www/browser/assets/vs/language/json/monaco.contribution.js +1 -0
- package/www/browser/assets/vs/language/typescript/monaco.contribution.js +1 -0
- package/www/browser/assets/vs/less-C0eDYdqa.js +2 -0
- package/www/browser/assets/vs/lexon-iON-Kj97.js +1 -0
- package/www/browser/assets/vs/liquid-DqKjdPGy.js +1 -0
- package/www/browser/assets/vs/loader.js +1368 -0
- package/www/browser/assets/vs/lspLanguageFeatures-kM9O9rjY.js +4 -0
- package/www/browser/assets/vs/lua-DtygF91M.js +1 -0
- package/www/browser/assets/vs/m3-CsR4AuFi.js +1 -0
- package/www/browser/assets/vs/markdown-C_rD0bIw.js +1 -0
- package/www/browser/assets/vs/mdx-DEWtB1K5.js +1 -0
- package/www/browser/assets/vs/mips-CiYP61RB.js +1 -0
- package/www/browser/assets/vs/monaco.contribution-D2OdxNBt.js +1 -0
- package/www/browser/assets/vs/monaco.contribution-DO3azKX8.js +1 -0
- package/www/browser/assets/vs/monaco.contribution-EcChJV6a.js +1 -0
- package/www/browser/assets/vs/monaco.contribution-qLAYrEOP.js +1 -0
- package/www/browser/assets/vs/msdax-C38-sJlp.js +1 -0
- package/www/browser/assets/vs/mysql-CdtbpvbG.js +1 -0
- package/www/browser/assets/vs/nls.messages-loader.js +1 -0
- package/www/browser/assets/vs/nls.messages.cs.js.js +17 -0
- package/www/browser/assets/vs/nls.messages.de.js.js +17 -0
- package/www/browser/assets/vs/nls.messages.es.js.js +17 -0
- package/www/browser/assets/vs/nls.messages.fr.js.js +15 -0
- package/www/browser/assets/vs/nls.messages.it.js.js +15 -0
- package/www/browser/assets/vs/nls.messages.ja.js.js +17 -0
- package/www/browser/assets/vs/nls.messages.js.js +10 -0
- package/www/browser/assets/vs/nls.messages.ko.js.js +25 -0
- package/www/browser/assets/vs/nls.messages.pl.js.js +17 -0
- package/www/browser/assets/vs/nls.messages.pt-br.js.js +6 -0
- package/www/browser/assets/vs/nls.messages.ru.js.js +17 -0
- package/www/browser/assets/vs/nls.messages.tr.js.js +15 -0
- package/www/browser/assets/vs/nls.messages.zh-cn.js.js +17 -0
- package/www/browser/assets/vs/nls.messages.zh-tw.js.js +15 -0
- package/www/browser/assets/vs/objective-c-CntZFaHX.js +1 -0
- package/www/browser/assets/vs/pascal-r6kuqfl_.js +1 -0
- package/www/browser/assets/vs/pascaligo-BiXoTmXh.js +1 -0
- package/www/browser/assets/vs/perl-DABw_TcH.js +1 -0
- package/www/browser/assets/vs/pgsql-me_jFXeX.js +1 -0
- package/www/browser/assets/vs/php-D_kh-9LK.js +1 -0
- package/www/browser/assets/vs/pla-VfZjczW0.js +1 -0
- package/www/browser/assets/vs/postiats-BBSzz8Pk.js +1 -0
- package/www/browser/assets/vs/powerquery-Dt-g_2cc.js +1 -0
- package/www/browser/assets/vs/powershell-B-7ap1zc.js +1 -0
- package/www/browser/assets/vs/protobuf-BmtuEB1A.js +2 -0
- package/www/browser/assets/vs/pug-BRpRNeEb.js +1 -0
- package/www/browser/assets/vs/python-Cr0UkIbn.js +1 -0
- package/www/browser/assets/vs/qsharp-BzsFaUU9.js +1 -0
- package/www/browser/assets/vs/r-f8dDdrp4.js +1 -0
- package/www/browser/assets/vs/razor-BYAHOTkz.js +1 -0
- package/www/browser/assets/vs/redis-fvZQY4PI.js +1 -0
- package/www/browser/assets/vs/redshift-45Et0LQi.js +1 -0
- package/www/browser/assets/vs/restructuredtext-C7UUFKFD.js +1 -0
- package/www/browser/assets/vs/ruby-CZO8zYTz.js +1 -0
- package/www/browser/assets/vs/rust-Bfetafyc.js +1 -0
- package/www/browser/assets/vs/sb-3GYllVck.js +1 -0
- package/www/browser/assets/vs/scala-foMgrKo1.js +1 -0
- package/www/browser/assets/vs/scheme-CHdMtr7p.js +1 -0
- package/www/browser/assets/vs/scss-C1cmLt9V.js +3 -0
- package/www/browser/assets/vs/shell-ClXCKCEW.js +1 -0
- package/www/browser/assets/vs/solidity-MZ6ExpPy.js +1 -0
- package/www/browser/assets/vs/sophia-DWkuSsPQ.js +1 -0
- package/www/browser/assets/vs/sparql-AUGFYSyk.js +1 -0
- package/www/browser/assets/vs/sql-32GpJSV2.js +1 -0
- package/www/browser/assets/vs/st-CuDFIVZ_.js +1 -0
- package/www/browser/assets/vs/swift-n-2HociN.js +3 -0
- package/www/browser/assets/vs/systemverilog-Ch4vA8Yt.js +1 -0
- package/www/browser/assets/vs/tcl-D74tq1nH.js +1 -0
- package/www/browser/assets/vs/tsMode-CZz1Umrk.js +11 -0
- package/www/browser/assets/vs/twig-C6taOxMV.js +1 -0
- package/www/browser/assets/vs/typescript-DfOrAzoV.js +1 -0
- package/www/browser/assets/vs/typespec-D-PIh9Xw.js +1 -0
- package/www/browser/assets/vs/vb-Dyb2648j.js +1 -0
- package/www/browser/assets/vs/wgsl-BhLXMOR0.js +298 -0
- package/www/browser/assets/vs/workers-DcJshg-q.js +1 -0
- package/www/browser/assets/vs/xml-CdsdnY8S.js +1 -0
- package/www/browser/assets/vs/yaml-DYGvmE88.js +1 -0
- package/www/browser/chunk-2BZRE4G7.js +1 -0
- package/www/browser/chunk-2X3MRS27.js +1 -0
- package/www/browser/chunk-4KETC6EB.js +1 -0
- package/www/browser/{chunk-SNCDDYQR.js → chunk-5T5KA5PG.js} +1 -1
- package/www/browser/chunk-6CGHNKJI.js +1 -0
- package/www/browser/chunk-76TVIB33.js +63 -0
- package/www/browser/chunk-7J24TP36.js +1 -0
- package/www/browser/chunk-ACAZUX6C.js +1 -0
- package/www/browser/chunk-B6MBYCXI.js +1 -0
- package/www/browser/chunk-BYEU6KGP.js +2 -0
- package/www/browser/chunk-CZ5AZ3VW.js +1 -0
- package/www/browser/chunk-DW7F5PEA.js +1 -0
- package/www/browser/chunk-DXF7BVK5.js +1 -0
- package/www/browser/{chunk-HEKO7RQP.js → chunk-EEVPZGEY.js} +1 -1
- package/www/browser/chunk-G2W3B7TJ.js +1 -0
- package/www/browser/chunk-GDWS2L66.js +1 -0
- package/www/browser/chunk-HGONFYP6.js +1 -0
- package/www/browser/chunk-HHBPULJW.js +2 -0
- package/www/browser/chunk-HRXCR3IN.js +1 -0
- package/www/browser/chunk-INL2PELS.js +1 -0
- package/www/browser/chunk-JHMEKUZ5.js +1 -0
- package/www/browser/{chunk-OC62FHHS.js → chunk-JU3TEDBV.js} +2 -2
- package/www/browser/chunk-JZULA5JV.js +1 -0
- package/www/browser/{chunk-HZ73CM45.js → chunk-KVFR7GFV.js} +1 -1
- package/www/browser/chunk-L5D75AMV.js +1 -0
- package/www/browser/chunk-L7TMCSHV.js +1 -0
- package/www/browser/{chunk-E6LF4XBJ.js → chunk-LQ5OXSW7.js} +2 -2
- package/www/browser/chunk-MVQTKINJ.js +1 -0
- package/www/browser/chunk-N4LRZJBP.js +1 -0
- package/www/browser/chunk-O2EYEF7J.js +1 -0
- package/www/browser/chunk-OMDHJIUB.js +1 -0
- package/www/browser/chunk-OWUAAOHW.js +2 -0
- package/www/browser/chunk-PIK5YPIB.js +1 -0
- package/www/browser/chunk-RHLQRQDK.js +9 -0
- package/www/browser/chunk-RW2JPJV7.js +1 -0
- package/www/browser/chunk-S3SJ4VVM.js +11 -0
- package/www/browser/chunk-SPRWNZHF.js +15 -0
- package/www/browser/chunk-SQQNR223.js +1 -0
- package/www/browser/chunk-SVQWPHF5.js +1 -0
- package/www/browser/{chunk-56SDBJDG.js → chunk-SYCNSLAW.js} +4 -4
- package/www/browser/chunk-T3KK7ZXB.js +2 -0
- package/www/browser/chunk-TMX5TTV3.js +1 -0
- package/www/browser/chunk-UFY3FLDK.js +1 -0
- package/www/browser/chunk-UJOHBN2Y.js +1 -0
- package/www/browser/chunk-UQGCUFNM.js +1 -0
- package/www/browser/chunk-UXXWRMM6.js +1 -0
- package/www/browser/chunk-UZRJGJTD.js +2 -0
- package/www/browser/chunk-WD4IAQR3.js +1 -0
- package/www/browser/chunk-WF2QTF5L.js +1 -0
- package/www/browser/chunk-WI67LAOV.js +4 -0
- package/www/browser/chunk-WNCM6QKB.js +1 -0
- package/www/browser/chunk-XJ5KZQNN.js +1 -0
- package/www/browser/chunk-YETDFSQE.js +1 -0
- package/www/browser/chunk-YMTC5GZK.js +1 -0
- package/www/browser/chunk-YVZHJ76K.js +1 -0
- package/www/browser/chunk-ZNTJRLVH.js +1 -0
- package/www/browser/favicon.ico +0 -0
- package/www/browser/index.html +2 -2
- package/www/browser/main-6LN5C22E.js +34 -0
- package/www/browser/scripts-U25HCVEI.js +6 -0
- package/www/browser/chunk-25RT7L2O.js +0 -1
- package/www/browser/chunk-2P5WKSWB.js +0 -5
- package/www/browser/chunk-2XZHN52E.js +0 -1
- package/www/browser/chunk-3MBM5AMR.js +0 -1
- package/www/browser/chunk-3V5PIKHE.js +0 -11
- package/www/browser/chunk-42JVTVYH.js +0 -1
- package/www/browser/chunk-4IQIZX7Y.js +0 -1
- package/www/browser/chunk-4UAHOL42.js +0 -1
- package/www/browser/chunk-5DD65JMJ.js +0 -1
- package/www/browser/chunk-5EQOKH7G.js +0 -12
- package/www/browser/chunk-6JH45SUC.js +0 -1
- package/www/browser/chunk-6X6PEDE5.js +0 -1
- package/www/browser/chunk-AI6SNMEH.js +0 -1
- package/www/browser/chunk-AMXCOT2F.js +0 -1
- package/www/browser/chunk-DP3VTELD.js +0 -1
- package/www/browser/chunk-EMK65RIU.js +0 -1
- package/www/browser/chunk-EYGWZTTT.js +0 -1
- package/www/browser/chunk-GKY4LJF4.js +0 -1
- package/www/browser/chunk-HJC5MNP5.js +0 -1
- package/www/browser/chunk-ITXWAN4J.js +0 -1
- package/www/browser/chunk-IZNTCWTR.js +0 -1
- package/www/browser/chunk-KN3WZJH7.js +0 -1
- package/www/browser/chunk-KPO75P5E.js +0 -1
- package/www/browser/chunk-LWBZC6ZL.js +0 -2
- package/www/browser/chunk-NYXWJKSW.js +0 -1
- package/www/browser/chunk-QM5ROT66.js +0 -1
- package/www/browser/chunk-SJG2JCPL.js +0 -4
- package/www/browser/chunk-W633D3VG.js +0 -1
- package/www/browser/chunk-X3HFJACM.js +0 -2
- package/www/browser/chunk-YFAKNLWB.js +0 -2
- package/www/browser/chunk-ZSPNEYSK.js +0 -1
- package/www/browser/main-O5GAJRDW.js +0 -34
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = hubRoutes;
|
|
4
|
+
const core_1 = require("@yinuo-ngm/core");
|
|
5
|
+
const DEFAULT_HUB_PUBLIC_BASE_URL = "http://192.168.1.31:7070/api/public";
|
|
6
|
+
function normalizeText(value, maxLen, fieldName) {
|
|
7
|
+
if (value === undefined || value === null)
|
|
8
|
+
return undefined;
|
|
9
|
+
if (typeof value !== "string") {
|
|
10
|
+
throw new core_1.AppError("BAD_REQUEST", `${fieldName} must be string`);
|
|
11
|
+
}
|
|
12
|
+
const text = value.trim();
|
|
13
|
+
if (text.length > maxLen) {
|
|
14
|
+
throw new core_1.AppError("BAD_REQUEST", `${fieldName} length must <= ${maxLen}`);
|
|
15
|
+
}
|
|
16
|
+
return text;
|
|
17
|
+
}
|
|
18
|
+
function validateBody(input) {
|
|
19
|
+
if (!input || typeof input !== "object") {
|
|
20
|
+
throw new core_1.AppError("BAD_REQUEST", "invalid feedback payload");
|
|
21
|
+
}
|
|
22
|
+
const body = input;
|
|
23
|
+
const category = body.category;
|
|
24
|
+
const title = normalizeText(body.title, 120, "title");
|
|
25
|
+
const content = normalizeText(body.content, 5000, "content");
|
|
26
|
+
const projectKey = normalizeText(body.projectKey, 80, "projectKey");
|
|
27
|
+
const contact = normalizeText(body.contact, 120, "contact");
|
|
28
|
+
const clientName = normalizeText(body.clientName, 120, "clientName");
|
|
29
|
+
const clientVersion = normalizeText(body.clientVersion, 60, "clientVersion");
|
|
30
|
+
const osInfo = normalizeText(body.osInfo, 200, "osInfo");
|
|
31
|
+
if (!category || !["bug", "suggestion", "feature", "other"].includes(category)) {
|
|
32
|
+
throw new core_1.AppError("BAD_REQUEST", "invalid feedback category");
|
|
33
|
+
}
|
|
34
|
+
if (!title) {
|
|
35
|
+
throw new core_1.AppError("BAD_REQUEST", "feedback title is required");
|
|
36
|
+
}
|
|
37
|
+
if (!content) {
|
|
38
|
+
throw new core_1.AppError("BAD_REQUEST", "feedback content is required");
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
category,
|
|
42
|
+
title,
|
|
43
|
+
content,
|
|
44
|
+
projectKey,
|
|
45
|
+
contact,
|
|
46
|
+
clientName,
|
|
47
|
+
clientVersion,
|
|
48
|
+
osInfo,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function resolveClientIp(req) {
|
|
52
|
+
const xForwardedFor = req.headers?.["x-forwarded-for"];
|
|
53
|
+
if (typeof xForwardedFor === "string" && xForwardedFor.trim()) {
|
|
54
|
+
return xForwardedFor.split(",")[0]?.trim() || undefined;
|
|
55
|
+
}
|
|
56
|
+
return req.ip || req.socket?.remoteAddress || undefined;
|
|
57
|
+
}
|
|
58
|
+
async function hubRoutes(app) {
|
|
59
|
+
app.post("/feedback", async (req) => {
|
|
60
|
+
const body = validateBody(req.body);
|
|
61
|
+
const baseUrl = (process.env.NGM_HUB_PUBLIC_BASE_URL || DEFAULT_HUB_PUBLIC_BASE_URL).replace(/\/+$/, "");
|
|
62
|
+
const targetUrl = `${baseUrl}/feedbacks`;
|
|
63
|
+
let response;
|
|
64
|
+
try {
|
|
65
|
+
response = await fetch(targetUrl, {
|
|
66
|
+
method: "POST",
|
|
67
|
+
headers: {
|
|
68
|
+
"content-type": "application/json",
|
|
69
|
+
},
|
|
70
|
+
body: JSON.stringify({
|
|
71
|
+
source: "web",
|
|
72
|
+
category: body.category,
|
|
73
|
+
title: body.title,
|
|
74
|
+
content: body.content,
|
|
75
|
+
projectKey: body.projectKey,
|
|
76
|
+
contact: body.contact,
|
|
77
|
+
clientName: body.clientName,
|
|
78
|
+
clientVersion: body.clientVersion,
|
|
79
|
+
osInfo: body.osInfo,
|
|
80
|
+
clientIp: resolveClientIp(req),
|
|
81
|
+
}),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
throw new core_1.AppError("UNKNOWN_ERROR", "failed to connect hub service", { cause: error?.message || String(error), targetUrl });
|
|
86
|
+
}
|
|
87
|
+
let payload = null;
|
|
88
|
+
try {
|
|
89
|
+
payload = await response.json();
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
payload = null;
|
|
93
|
+
}
|
|
94
|
+
if (!response.ok) {
|
|
95
|
+
const message = payload?.message || `hub response error (${response.status})`;
|
|
96
|
+
throw new core_1.AppError("UNKNOWN_ERROR", message, { status: response.status, payload });
|
|
97
|
+
}
|
|
98
|
+
if (payload?.code !== "OK") {
|
|
99
|
+
throw new core_1.AppError("UNKNOWN_ERROR", payload?.message || "hub feedback submit failed", { payload });
|
|
100
|
+
}
|
|
101
|
+
return payload?.data ?? payload;
|
|
102
|
+
});
|
|
103
|
+
}
|
package/lib/routes/index.js
CHANGED
|
@@ -14,9 +14,12 @@ const sprite_routes_1 = require("./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
|
+
const nginx_routes_1 = require("./nginx.routes");
|
|
17
18
|
const svn_routes_1 = __importDefault(require("./svn.routes"));
|
|
18
19
|
const sprite_browse_routes_1 = __importDefault(require("./sprite-browse.routes"));
|
|
19
20
|
const static_files_routes_1 = __importDefault(require("./static-files.routes"));
|
|
21
|
+
const hub_routes_1 = __importDefault(require("./hub.routes"));
|
|
22
|
+
const node_version_routes_1 = __importDefault(require("./node-version.routes"));
|
|
20
23
|
async function routes(fastify) {
|
|
21
24
|
await fastify.register(system_routes_1.default);
|
|
22
25
|
await fastify.register(task_routes_1.default, { prefix: '/api/tasks' });
|
|
@@ -30,9 +33,13 @@ async function routes(fastify) {
|
|
|
30
33
|
await fastify.register(svn_routes_1.default, { prefix: '/api/svn' });
|
|
31
34
|
await fastify.register(sprite_browse_routes_1.default, { prefix: '/api/sprite/browse' });
|
|
32
35
|
await fastify.register(static_files_routes_1.default, { prefix: '/api/static' });
|
|
36
|
+
await fastify.register(hub_routes_1.default, { prefix: '/api/hub' });
|
|
33
37
|
await fastify.register(api_client_1.apiClientEnvsRoutes, { prefix: '/api/client/envs' });
|
|
34
38
|
await fastify.register(api_client_1.apiClientRequestsRoutes, { prefix: '/api/client/requests' });
|
|
35
39
|
await fastify.register(api_client_1.apiClientHistoryRoutes, { prefix: '/api/client/history' });
|
|
36
40
|
await fastify.register(api_client_1.apiClientSendRoutes, { prefix: '/api/client/send' });
|
|
37
41
|
await fastify.register(api_client_1.apiClientCollectionsRoutes, { prefix: '/api/client/collections' });
|
|
42
|
+
await fastify.register(api_client_1.apiClientHubTokenRoutes, { prefix: '/api/client/hub-token' });
|
|
43
|
+
await fastify.register(nginx_routes_1.nginxRoutes, { prefix: '/api/nginx' });
|
|
44
|
+
await fastify.register(node_version_routes_1.default, { prefix: '/api/node-version' });
|
|
38
45
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerNginxConfigRoutes = registerNginxConfigRoutes;
|
|
4
|
+
const nginx_route_context_1 = require("./nginx-route.context");
|
|
5
|
+
function registerNginxConfigRoutes(context) {
|
|
6
|
+
const { fastify, nginx, normalizeFsPath, ensureManageableConfigFile } = context;
|
|
7
|
+
fastify.get('/config', async (_request, reply) => {
|
|
8
|
+
try {
|
|
9
|
+
const config = await nginx.config.readMainConfig();
|
|
10
|
+
return reply.send({
|
|
11
|
+
success: true,
|
|
12
|
+
config,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
fastify.put('/config', async (request, reply) => {
|
|
20
|
+
const { content } = request.body;
|
|
21
|
+
try {
|
|
22
|
+
await nginx.config.writeMainConfig(content);
|
|
23
|
+
return reply.send({
|
|
24
|
+
success: true,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
fastify.post('/config/validate', async (request, reply) => {
|
|
32
|
+
const { content } = request.body;
|
|
33
|
+
const result = await nginx.config.validateConfig(content);
|
|
34
|
+
return reply.send(result);
|
|
35
|
+
});
|
|
36
|
+
fastify.get('/config/files', async (_request, reply) => {
|
|
37
|
+
try {
|
|
38
|
+
const files = await nginx.config.getIncludedConfigs();
|
|
39
|
+
return reply.send({
|
|
40
|
+
success: true,
|
|
41
|
+
files,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
fastify.get('/config/file', async (request, reply) => {
|
|
49
|
+
try {
|
|
50
|
+
const filePath = await ensureManageableConfigFile(request.query?.filePath);
|
|
51
|
+
const mainConfig = await nginx.config.readMainConfig();
|
|
52
|
+
const isMainConfig = normalizeFsPath(mainConfig.mainConfigPath) === normalizeFsPath(filePath);
|
|
53
|
+
if (isMainConfig) {
|
|
54
|
+
return reply.send({
|
|
55
|
+
success: true,
|
|
56
|
+
config: mainConfig,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const content = await nginx.config.readConfigFile(filePath);
|
|
60
|
+
const isWritable = await nginx.config.isConfigFileWritable(filePath);
|
|
61
|
+
return reply.send({
|
|
62
|
+
success: true,
|
|
63
|
+
config: {
|
|
64
|
+
mainConfigPath: filePath,
|
|
65
|
+
content,
|
|
66
|
+
isWritable,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
fastify.put('/config/file', async (request, reply) => {
|
|
75
|
+
try {
|
|
76
|
+
const filePath = await ensureManageableConfigFile(request.body?.filePath);
|
|
77
|
+
const content = request.body?.content ?? '';
|
|
78
|
+
const mainConfig = await nginx.config.readMainConfig();
|
|
79
|
+
const isMainConfig = normalizeFsPath(mainConfig.mainConfigPath) === normalizeFsPath(filePath);
|
|
80
|
+
if (isMainConfig) {
|
|
81
|
+
await nginx.config.writeMainConfig(content);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
await nginx.config.writeConfigFile(filePath, content);
|
|
85
|
+
}
|
|
86
|
+
return reply.send({
|
|
87
|
+
success: true,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerNginxLifecycleRoutes = registerNginxLifecycleRoutes;
|
|
4
|
+
const nginx_binding_store_1 = require("../../plugins/nginx.binding.store");
|
|
5
|
+
const nginx_route_context_1 = require("./nginx-route.context");
|
|
6
|
+
function registerNginxLifecycleRoutes(context) {
|
|
7
|
+
const { fastify, nginx } = context;
|
|
8
|
+
fastify.get('/status', async (_request, reply) => {
|
|
9
|
+
const instance = nginx.service.getInstance();
|
|
10
|
+
const status = await nginx.service.getStatus();
|
|
11
|
+
return reply.send({
|
|
12
|
+
instance,
|
|
13
|
+
status,
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
fastify.get('/stats', async (_request, reply) => {
|
|
17
|
+
try {
|
|
18
|
+
const instance = nginx.service.getInstance();
|
|
19
|
+
const status = await nginx.service.getStatus();
|
|
20
|
+
const servers = await nginx.server.getAllServers();
|
|
21
|
+
const enabled = servers.filter(item => item.enabled).length;
|
|
22
|
+
return reply.send({
|
|
23
|
+
success: true,
|
|
24
|
+
instance,
|
|
25
|
+
status,
|
|
26
|
+
serverSummary: {
|
|
27
|
+
total: servers.length,
|
|
28
|
+
enabled,
|
|
29
|
+
disabled: Math.max(servers.length - enabled, 0),
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
fastify.post('/bind', async (request, reply) => {
|
|
38
|
+
const { path } = request.body;
|
|
39
|
+
try {
|
|
40
|
+
const instance = await nginx.service.bind(path);
|
|
41
|
+
try {
|
|
42
|
+
await (0, nginx_binding_store_1.savePersistedNginxPath)(instance.path);
|
|
43
|
+
}
|
|
44
|
+
catch (persistError) {
|
|
45
|
+
fastify.log.warn(`[nginx] binding persisted failed: ${String(persistError)}`);
|
|
46
|
+
}
|
|
47
|
+
return reply.send({
|
|
48
|
+
success: true,
|
|
49
|
+
instance,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
fastify.post('/unbind', async (_request, reply) => {
|
|
57
|
+
nginx.service.unbind();
|
|
58
|
+
try {
|
|
59
|
+
await (0, nginx_binding_store_1.clearPersistedNginxPath)();
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
fastify.log.warn(`[nginx] clear persisted binding failed: ${String(error)}`);
|
|
63
|
+
}
|
|
64
|
+
return reply.send({
|
|
65
|
+
success: true,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
fastify.post('/start', async (_request, reply) => {
|
|
69
|
+
const result = await nginx.service.start();
|
|
70
|
+
if (result.success) {
|
|
71
|
+
fastify.core.sysLog.info({ scope: 'system', source: 'server', text: '[Nginx] 启动成功' });
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
fastify.core.sysLog.error({ scope: 'system', source: 'server', text: `[Nginx] 启动失败: ${result.error || '未知错误'}` });
|
|
75
|
+
}
|
|
76
|
+
return reply.send(result);
|
|
77
|
+
});
|
|
78
|
+
fastify.post('/stop', async (_request, reply) => {
|
|
79
|
+
const result = await nginx.service.stop();
|
|
80
|
+
if (result.success) {
|
|
81
|
+
fastify.core.sysLog.warn({ scope: 'system', source: 'server', text: '[Nginx] 已停止' });
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
fastify.core.sysLog.error({ scope: 'system', source: 'server', text: `[Nginx] 停止失败: ${result.error || '未知错误'}` });
|
|
85
|
+
}
|
|
86
|
+
return reply.send(result);
|
|
87
|
+
});
|
|
88
|
+
fastify.post('/reload', async (_request, reply) => {
|
|
89
|
+
const result = await nginx.service.reload();
|
|
90
|
+
if (result.success) {
|
|
91
|
+
fastify.core.sysLog.info({ scope: 'system', source: 'server', text: '[Nginx] 配置重载成功' });
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
fastify.core.sysLog.error({ scope: 'system', source: 'server', text: `[Nginx] 重载失败: ${result.error || '未知错误'}` });
|
|
95
|
+
}
|
|
96
|
+
return reply.send(result);
|
|
97
|
+
});
|
|
98
|
+
fastify.post('/test', async (_request, reply) => {
|
|
99
|
+
const result = await nginx.service.testConfig();
|
|
100
|
+
if (result.valid) {
|
|
101
|
+
fastify.core.sysLog.success({ scope: 'system', source: 'server', text: '[Nginx] 配置检测通过' });
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
fastify.core.sysLog.error({ scope: 'system', source: 'server', text: `[Nginx] 配置检测失败: ${(result.errors || []).join(', ')}` });
|
|
105
|
+
}
|
|
106
|
+
return reply.send(result);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerNginxLogRoutes = registerNginxLogRoutes;
|
|
4
|
+
const nginx_route_context_1 = require("./nginx-route.context");
|
|
5
|
+
function registerNginxLogRoutes(context) {
|
|
6
|
+
const { fastify, nginx } = context;
|
|
7
|
+
fastify.get('/logs/error', async (request, reply) => {
|
|
8
|
+
try {
|
|
9
|
+
const tail = Math.max(1, Math.min(1000, Number(request.query?.tail ?? 100)));
|
|
10
|
+
const lines = await nginx.log.readLogTail('error', tail);
|
|
11
|
+
return reply.send({
|
|
12
|
+
success: true,
|
|
13
|
+
lines,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
fastify.get('/logs/access', async (request, reply) => {
|
|
21
|
+
try {
|
|
22
|
+
const tail = Math.max(1, Math.min(1000, Number(request.query?.tail ?? 100)));
|
|
23
|
+
const lines = await nginx.log.readLogTail('access', tail);
|
|
24
|
+
return reply.send({
|
|
25
|
+
success: true,
|
|
26
|
+
lines,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
fastify.get('/logs/info', async (_request, reply) => {
|
|
34
|
+
try {
|
|
35
|
+
const errorPath = nginx.log.getLogFilePath('error');
|
|
36
|
+
const accessPath = nginx.log.getLogFilePath('access');
|
|
37
|
+
return reply.send({
|
|
38
|
+
success: true,
|
|
39
|
+
errorLog: errorPath,
|
|
40
|
+
accessLog: accessPath,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerNginxModuleRoutes = registerNginxModuleRoutes;
|
|
4
|
+
const nginx_route_context_1 = require("./nginx-route.context");
|
|
5
|
+
function registerNginxModuleRoutes(context) {
|
|
6
|
+
const { fastify, nginx } = context;
|
|
7
|
+
fastify.get('/upstreams', async (_request, reply) => {
|
|
8
|
+
try {
|
|
9
|
+
const upstreams = await nginx.module.getUpstreams();
|
|
10
|
+
return reply.send({
|
|
11
|
+
success: true,
|
|
12
|
+
upstreams,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
fastify.put('/upstreams', async (request, reply) => {
|
|
20
|
+
try {
|
|
21
|
+
await nginx.module.saveUpstreams(request.body?.upstreams || []);
|
|
22
|
+
return reply.send({
|
|
23
|
+
success: true,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
fastify.get('/ssl/certificates', async (_request, reply) => {
|
|
31
|
+
try {
|
|
32
|
+
const certificates = await nginx.module.getSslCertificates();
|
|
33
|
+
return reply.send({
|
|
34
|
+
success: true,
|
|
35
|
+
certificates,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
fastify.put('/ssl/certificates', async (request, reply) => {
|
|
43
|
+
try {
|
|
44
|
+
await nginx.module.saveSslCertificates(request.body?.certificates || []);
|
|
45
|
+
return reply.send({
|
|
46
|
+
success: true,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
fastify.get('/traffic', async (_request, reply) => {
|
|
54
|
+
try {
|
|
55
|
+
const traffic = await nginx.module.getTrafficConfig();
|
|
56
|
+
return reply.send({
|
|
57
|
+
success: true,
|
|
58
|
+
traffic,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
fastify.put('/traffic', async (request, reply) => {
|
|
66
|
+
try {
|
|
67
|
+
await nginx.module.saveTrafficConfig(request.body);
|
|
68
|
+
return reply.send({
|
|
69
|
+
success: true,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
fastify.get('/performance', async (_request, reply) => {
|
|
77
|
+
try {
|
|
78
|
+
const performance = await nginx.module.getPerformanceConfig();
|
|
79
|
+
return reply.send({
|
|
80
|
+
success: true,
|
|
81
|
+
performance,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
fastify.put('/performance', async (request, reply) => {
|
|
89
|
+
try {
|
|
90
|
+
await nginx.module.savePerformanceConfig(request.body);
|
|
91
|
+
return reply.send({
|
|
92
|
+
success: true,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
fastify.get('/module/settings', async (_request, reply) => {
|
|
100
|
+
try {
|
|
101
|
+
const settings = await nginx.module.getModuleSettings();
|
|
102
|
+
return reply.send({
|
|
103
|
+
success: true,
|
|
104
|
+
settings,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
fastify.put('/module/settings', async (request, reply) => {
|
|
112
|
+
try {
|
|
113
|
+
const settings = await nginx.module.saveModuleSettings(request.body || {});
|
|
114
|
+
return reply.send({
|
|
115
|
+
success: true,
|
|
116
|
+
settings,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FastifyInstance, FastifyReply } from 'fastify';
|
|
2
|
+
export interface NginxRouteContext {
|
|
3
|
+
fastify: FastifyInstance;
|
|
4
|
+
nginx: FastifyInstance['nginx'];
|
|
5
|
+
normalizeFsPath: (filePath: string) => string;
|
|
6
|
+
ensureManageableConfigFile: (rawPath?: string) => Promise<string>;
|
|
7
|
+
}
|
|
8
|
+
export declare function createNginxRouteContext(fastify: FastifyInstance): NginxRouteContext;
|
|
9
|
+
export declare function sendBadRequest(reply: FastifyReply, error: unknown): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createNginxRouteContext = createNginxRouteContext;
|
|
4
|
+
exports.sendBadRequest = sendBadRequest;
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const core_1 = require("@yinuo-ngm/core");
|
|
7
|
+
function createNginxRouteContext(fastify) {
|
|
8
|
+
const nginx = fastify.nginx;
|
|
9
|
+
const normalizeFsPath = (filePath) => (0, path_1.resolve)(filePath).replace(/\\/g, '/').toLowerCase();
|
|
10
|
+
const ensureManageableConfigFile = async (rawPath) => {
|
|
11
|
+
const filePath = rawPath?.trim();
|
|
12
|
+
if (!filePath) {
|
|
13
|
+
throw new Error('配置文件路径不能为空');
|
|
14
|
+
}
|
|
15
|
+
const included = await nginx.config.getIncludedConfigs();
|
|
16
|
+
const includedSet = new Set(included.map(item => normalizeFsPath(item)));
|
|
17
|
+
const normalizedTarget = normalizeFsPath(filePath);
|
|
18
|
+
if (!includedSet.has(normalizedTarget)) {
|
|
19
|
+
throw new Error('配置文件不在当前可管理列表中');
|
|
20
|
+
}
|
|
21
|
+
return (0, path_1.resolve)(filePath);
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
fastify,
|
|
25
|
+
nginx,
|
|
26
|
+
normalizeFsPath,
|
|
27
|
+
ensureManageableConfigFile,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function sendBadRequest(reply, error) {
|
|
31
|
+
const message = error instanceof Error ? error.message : String(error ?? '未知错误');
|
|
32
|
+
throw new core_1.AppError('BAD_REQUEST', message, {
|
|
33
|
+
route: reply.request?.url,
|
|
34
|
+
method: reply.request?.method,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerNginxServerRoutes = registerNginxServerRoutes;
|
|
4
|
+
const core_1 = require("@yinuo-ngm/core");
|
|
5
|
+
const nginx_route_context_1 = require("./nginx-route.context");
|
|
6
|
+
function registerNginxServerRoutes(context) {
|
|
7
|
+
const { fastify, nginx } = context;
|
|
8
|
+
fastify.get('/servers', async (_request, reply) => {
|
|
9
|
+
try {
|
|
10
|
+
const servers = await nginx.server.getAllServers();
|
|
11
|
+
return reply.send({
|
|
12
|
+
success: true,
|
|
13
|
+
servers,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
fastify.get('/servers/:id', async (request, reply) => {
|
|
21
|
+
const { id } = request.params;
|
|
22
|
+
try {
|
|
23
|
+
const server = await nginx.server.getServer(id);
|
|
24
|
+
if (!server) {
|
|
25
|
+
throw new core_1.AppError('NOT_FOUND', 'Server 不存在');
|
|
26
|
+
}
|
|
27
|
+
return reply.send({
|
|
28
|
+
success: true,
|
|
29
|
+
server,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
fastify.post('/servers', async (request, reply) => {
|
|
37
|
+
try {
|
|
38
|
+
const server = await nginx.server.createServer(request.body);
|
|
39
|
+
return reply.send({
|
|
40
|
+
success: true,
|
|
41
|
+
server,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
fastify.put('/servers/:id', async (request, reply) => {
|
|
49
|
+
const { id } = request.params;
|
|
50
|
+
try {
|
|
51
|
+
const server = await nginx.server.updateServer(id, request.body);
|
|
52
|
+
return reply.send({
|
|
53
|
+
success: true,
|
|
54
|
+
server,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
fastify.delete('/servers/:id', async (request, reply) => {
|
|
62
|
+
const { id } = request.params;
|
|
63
|
+
try {
|
|
64
|
+
await nginx.server.deleteServer(id);
|
|
65
|
+
return reply.send({
|
|
66
|
+
success: true,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
fastify.patch('/servers/:id/enable', async (request, reply) => {
|
|
74
|
+
const { id } = request.params;
|
|
75
|
+
try {
|
|
76
|
+
await nginx.server.enableServer(id);
|
|
77
|
+
return reply.send({
|
|
78
|
+
success: true,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
fastify.patch('/servers/:id/disable', async (request, reply) => {
|
|
86
|
+
const { id } = request.params;
|
|
87
|
+
try {
|
|
88
|
+
await nginx.server.disableServer(id);
|
|
89
|
+
return reply.send({
|
|
90
|
+
success: true,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|