@kne/fastify-app-manager 0.1.23 → 0.1.24
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 +16 -4
- package/index.js +15 -0
- package/libs/controllers/app.js +2 -2
- package/libs/services/app.js +3 -3
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -211,6 +211,9 @@ await fastify.listen({ port: 3000 });
|
|
|
211
211
|
| `pm2Defaults` | object | 否 | 见下表 | 全局 PM2 默认;可被应用 `pm2Config` 覆盖 |
|
|
212
212
|
| `createAuthenticate` | function | 否 | 见说明 | 返回 `onRequest` 钩子数组;默认 `fastify.account.authenticate.user` + `admin` |
|
|
213
213
|
| `createUserAuthenticate` | function | 否 | 见说明 | 应用中心等普通用户接口的 `onRequest` 钩子数组;默认尝试 `fastify.account.authenticate.user` |
|
|
214
|
+
| `enableGroup` | boolean | 否 | `true` | 是否在插件内部注册 `@kne/fastify-group` 提供应用分类接口;宿主已有分组服务时可设为 `false` |
|
|
215
|
+
| `groupName` | string | 否 | `'appManagerGroup'` | 内部分组插件的命名空间(`fastify[groupName]`),与宿主自己注册的 `group` 区分 |
|
|
216
|
+
| `groupDbTableNamePrefix` | string | 否 | `'t_'` | 分组表前缀,表名为前缀 + `snakeCase(groupName + 'Tag')`,默认 `t_app_manager_group_tag` |
|
|
214
217
|
| `upstreamHost` | string | 否 | `'127.0.0.1'` | 子应用进程监听地址:网关转发、WebSocket、就绪探测、端口探测与 `resolveSystemEnv` 的 `upstreamUrl` 共用 |
|
|
215
218
|
| `healthCheckPath` | string | 否 | `'/'` | 部署后就绪探测路径 |
|
|
216
219
|
| `healthCheckTimeoutMs` | number | 否 | `30000` | 探测总超时(毫秒) |
|
|
@@ -276,7 +279,7 @@ await fastify.listen({ port: 3000 });
|
|
|
276
279
|
| description | string | 否 | - | 描述 |
|
|
277
280
|
| category | object / string | 否 | - | 应用分类(应用中心分组用),写入 `options.category`;推荐传 fastify-group 分组对象,对象只保留 `{ code, name }`,字符串原样保存 |
|
|
278
281
|
| isPublic | boolean | 否 | `true` | 是否在公开应用中心展示,写入 `options.isPublic`;未设置视为公开 |
|
|
279
|
-
| entries | array | 否 | `[]` | 应用入口 `[{ label, path }]`,写入 `options.entries`;`path` 相对应用根(缺前导 `/` 自动补),缺 `label` 或 `path` 的项丢弃,同 `path`
|
|
282
|
+
| entries | array | 否 | `[]` | 应用入口 `[{ label, path, showInCenter }]`,写入 `options.entries`;`path` 相对应用根(缺前导 `/` 自动补),缺 `label` 或 `path` 的项丢弃,同 `path` 只保留第一项;`showInCenter` 为是否开放给前台(默认 `true`),为 `false` 时应用中心列表与 PWA 不返回该入口,管理端仍可见 |
|
|
280
283
|
| env | object | 否 | `{}` | 应用自有环境变量 |
|
|
281
284
|
| pm2Config | object | 否 | `{}` | PM2 覆盖项 |
|
|
282
285
|
| options | object | 否 | `{}` | 扩展字段;可含 `secretEnvKeys: string[]` 显式密钥键名 |
|
|
@@ -606,6 +609,13 @@ data: {"progressId":"p-1","step":"ready","status":"done","detail":null,"message"
|
|
|
606
609
|
|
|
607
610
|
返回 `{ pageData, totalCount }`,元素均为脱敏后的应用对象。
|
|
608
611
|
|
|
612
|
+
##### 应用分类 `{prefix}/group/*`
|
|
613
|
+
|
|
614
|
+
`enableGroup` 不为 `false` 时,插件内部注册 `@kne/fastify-group`,接口与其一致:`GET group/list`、`GET group/group-list`、`GET group/detail`、`POST group/save`、`POST group/remove`。应用分类使用 `type: 'app'`。
|
|
615
|
+
|
|
616
|
+
- 读接口(`list` / `group-list` / `detail`)**无需登录**,未登录的公开应用中心也能显示分类名称
|
|
617
|
+
- 写接口(`save` / `remove`)使用 `createAuthenticate` 鉴权
|
|
618
|
+
|
|
609
619
|
##### GET `{prefix}/app/center/list`
|
|
610
620
|
|
|
611
621
|
应用中心列表,使用 `createUserAuthenticate` 鉴权(普通登录用户可访问)。仅返回 `status: 'running'` 的应用,且只含公开字段(不含 env、端口、路径等)。
|
|
@@ -622,8 +632,8 @@ data: {"progressId":"p-1","step":"ready","status":"done","detail":null,"message"
|
|
|
622
632
|
"isPublic": true,
|
|
623
633
|
"pathUrl": "/app/demo/",
|
|
624
634
|
"entries": [
|
|
625
|
-
{ "label": "PC", "path": "/", "url": "/app/demo/" },
|
|
626
|
-
{ "label": "移动端", "path": "/mobile", "url": "/app/demo/mobile" }
|
|
635
|
+
{ "label": "PC", "path": "/", "showInCenter": true, "url": "/app/demo/" },
|
|
636
|
+
{ "label": "移动端", "path": "/mobile", "showInCenter": true, "url": "/app/demo/mobile" }
|
|
627
637
|
],
|
|
628
638
|
"deployment": null
|
|
629
639
|
}
|
|
@@ -632,6 +642,8 @@ data: {"progressId":"p-1","step":"ready","status":"done","detail":null,"message"
|
|
|
632
642
|
}
|
|
633
643
|
```
|
|
634
644
|
|
|
645
|
+
`entries` 只含 `showInCenter` 不为 `false` 的入口。
|
|
646
|
+
|
|
635
647
|
`deployment`:部署或启动补回部署目录进行中时为 `{ source: 'deploy' | 'restore' }`,此时应用暂不可访问;否则为 `null`。
|
|
636
648
|
|
|
637
649
|
##### GET `{prefix}/app/center/public-list`
|
|
@@ -930,7 +942,7 @@ data: {"name":"demo","ts":1791456608533,...}
|
|
|
930
942
|
| description | string / null | 描述 |
|
|
931
943
|
| env | object | 自有环境变量 |
|
|
932
944
|
| pm2Config | object | PM2 覆盖 |
|
|
933
|
-
| options | object | 扩展字段;`secretEnvKeys` 为显式密钥键名列表,`category` 为应用分类,`isPublic` 为是否公开(未设置视为公开),`entries` 为应用入口 `[{ label, path }]` |
|
|
945
|
+
| options | object | 扩展字段;`secretEnvKeys` 为显式密钥键名列表,`category` 为应用分类,`isPublic` 为是否公开(未设置视为公开),`entries` 为应用入口 `[{ label, path, showInCenter }]` |
|
|
934
946
|
| port | number | 分配端口 |
|
|
935
947
|
| status | string | `idle` / `deploying` / `running` / `stopped` / `error` |
|
|
936
948
|
| currentVersionId | string / null | 当前部署版本 id |
|
package/index.js
CHANGED
|
@@ -87,6 +87,11 @@ module.exports = fp(
|
|
|
87
87
|
}
|
|
88
88
|
return [];
|
|
89
89
|
},
|
|
90
|
+
/** 应用分类:插件内部注册 @kne/fastify-group,宿主已有分组服务时可关闭 */
|
|
91
|
+
enableGroup: true,
|
|
92
|
+
groupName: 'appManagerGroup',
|
|
93
|
+
/** 表名 = 前缀 + snakeCase(groupName + Tag),默认 t_app_manager_group_tag */
|
|
94
|
+
groupDbTableNamePrefix: 't_',
|
|
90
95
|
/** 普通登录用户可访问的接口(应用中心列表) */
|
|
91
96
|
createUserAuthenticate: () => {
|
|
92
97
|
if (fastify.account?.authenticate?.user) {
|
|
@@ -129,6 +134,16 @@ module.exports = fp(
|
|
|
129
134
|
options.createAuthenticate = withQueryToken(options.createAuthenticate);
|
|
130
135
|
options.createUserAuthenticate = withQueryToken(options.createUserAuthenticate);
|
|
131
136
|
|
|
137
|
+
// 分类读取需对未登录的公开应用中心开放,增删改沿用管理端鉴权
|
|
138
|
+
if (options.enableGroup !== false) {
|
|
139
|
+
await fastify.register(require('@kne/fastify-group'), {
|
|
140
|
+
name: options.groupName,
|
|
141
|
+
prefix: `${options.prefix}/group`,
|
|
142
|
+
dbTableNamePrefix: options.groupDbTableNamePrefix,
|
|
143
|
+
getAuthenticate: type => (type === 'read' ? [] : options.createAuthenticate())
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
132
147
|
// 宿主可能已注册(如 fastify-file-manager),重复注册会报错
|
|
133
148
|
if (!fastify.hasDecorator('multipartErrors')) {
|
|
134
149
|
await fastify.register(require('@fastify/multipart'), {
|
package/libs/controllers/app.js
CHANGED
|
@@ -30,7 +30,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
30
30
|
isPublic: { type: 'boolean' },
|
|
31
31
|
entries: {
|
|
32
32
|
type: ['array', 'null'],
|
|
33
|
-
items: { type: 'object', properties: { label: { type: 'string' }, path: { type: 'string' } } }
|
|
33
|
+
items: { type: 'object', properties: { label: { type: 'string' }, path: { type: 'string' }, showInCenter: { type: 'boolean' } } }
|
|
34
34
|
},
|
|
35
35
|
env: { type: 'object' },
|
|
36
36
|
pm2Config: { type: 'object' },
|
|
@@ -61,7 +61,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
61
61
|
isPublic: { type: 'boolean' },
|
|
62
62
|
entries: {
|
|
63
63
|
type: ['array', 'null'],
|
|
64
|
-
items: { type: 'object', properties: { label: { type: 'string' }, path: { type: 'string' } } }
|
|
64
|
+
items: { type: 'object', properties: { label: { type: 'string' }, path: { type: 'string' }, showInCenter: { type: 'boolean' } } }
|
|
65
65
|
},
|
|
66
66
|
env: { type: 'object' },
|
|
67
67
|
pm2Config: { type: 'object' },
|
package/libs/services/app.js
CHANGED
|
@@ -62,7 +62,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
62
62
|
}
|
|
63
63
|
return category.code ? { code: category.code, name: category.name || category.code } : null;
|
|
64
64
|
};
|
|
65
|
-
// 应用入口:label + 相对应用根的 path;去空、补前导 /、按 path
|
|
65
|
+
// 应用入口:label + 相对应用根的 path;去空、补前导 /、按 path 去重;showInCenter 未设置视为开放给前台
|
|
66
66
|
const normalizeEntries = entries => {
|
|
67
67
|
const seen = new Set();
|
|
68
68
|
return (Array.isArray(entries) ? entries : []).reduce((result, item) => {
|
|
@@ -74,7 +74,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
74
74
|
const entryPath = rawPath.startsWith('/') ? rawPath : `/${rawPath}`;
|
|
75
75
|
if (!seen.has(entryPath)) {
|
|
76
76
|
seen.add(entryPath);
|
|
77
|
-
result.push({ label, path: entryPath });
|
|
77
|
+
result.push({ label, path: entryPath, showInCenter: item?.showInCenter !== false });
|
|
78
78
|
}
|
|
79
79
|
return result;
|
|
80
80
|
}, []);
|
|
@@ -266,7 +266,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
266
266
|
category: app.options?.category || null,
|
|
267
267
|
isPublic: isAppPublic(app),
|
|
268
268
|
pathUrl: `${mountPrefix(app.name)}/`,
|
|
269
|
-
entries: resolveEntries(app),
|
|
269
|
+
entries: resolveEntries(app).filter(entry => entry.showInCenter),
|
|
270
270
|
deployment: active ? { source: active.source } : null
|
|
271
271
|
};
|
|
272
272
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kne/fastify-app-manager",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.24",
|
|
4
4
|
"description": "Fastify 单机应用市场插件:版本上传、PM2 托管、路径/域名反代与日志 SSE",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"@fastify/multipart": "^10.1.1",
|
|
76
76
|
"@fastify/reply-from": "^12.6.5",
|
|
77
77
|
"@kne/ensure-slash": "^0.1.0",
|
|
78
|
+
"@kne/fastify-group": "^0.2.6",
|
|
78
79
|
"@kne/pwa-document": "^0.1.0",
|
|
79
80
|
"adm-zip": "^0.6.0",
|
|
80
81
|
"ajv": "^8.17.1",
|