@dangao/bun-server 3.3.0 → 3.3.1
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/docs/microservice-config-center.md +2 -1
- package/docs/microservice-nacos.md +32 -5
- package/docs/microservice-service-registry.md +3 -6
- package/docs/microservice.md +0 -3
- package/docs/zh/microservice-config-center.md +2 -1
- package/docs/zh/microservice-nacos.md +32 -5
- package/docs/zh/microservice-service-registry.md +3 -6
- package/docs/zh/microservice.md +0 -3
- package/package.json +2 -2
|
@@ -21,6 +21,8 @@ The configuration center provides centralized configuration management capabilit
|
|
|
21
21
|
- **Configuration Priority**: Config center > Environment variables > Default configuration
|
|
22
22
|
- **Configuration Watching**: Watch for configuration changes and automatically refresh application configuration
|
|
23
23
|
|
|
24
|
+
> **Namespace**: For the Nacos public namespace (console default), omit `namespaceId`. Do not use the literal `"public"`. See [Nacos Integration - Namespace](./microservice-nacos.md#namespace).
|
|
25
|
+
|
|
24
26
|
## Quick Start
|
|
25
27
|
|
|
26
28
|
### 1. Register Configuration Center Module
|
|
@@ -37,7 +39,6 @@ app.registerModule(
|
|
|
37
39
|
nacos: {
|
|
38
40
|
client: {
|
|
39
41
|
serverList: ['http://localhost:8848'],
|
|
40
|
-
namespaceId: 'public',
|
|
41
42
|
username: 'nacos',
|
|
42
43
|
password: 'nacos',
|
|
43
44
|
},
|
|
@@ -5,6 +5,7 @@ This document introduces how to use Nacos as a configuration center and service
|
|
|
5
5
|
## Table of Contents
|
|
6
6
|
|
|
7
7
|
- [Overview](#overview)
|
|
8
|
+
- [Namespace](#namespace)
|
|
8
9
|
- [Nacos Installation](#nacos-installation)
|
|
9
10
|
- [Configuration Center Integration](#configuration-center-integration)
|
|
10
11
|
- [Service Registry Integration](#service-registry-integration)
|
|
@@ -20,6 +21,26 @@ Bun Server Framework provides Nacos 3.X support through the `@dangao/nacos-clien
|
|
|
20
21
|
- **Service Discovery**: Service instance querying and watching
|
|
21
22
|
- **Open API**: Based on Nacos 3.X Open API implementation
|
|
22
23
|
|
|
24
|
+
## Namespace
|
|
25
|
+
|
|
26
|
+
The default namespace shown as **public** in the Nacos console maps to an **empty string** `""` in the Open API, not the literal `"public"`.
|
|
27
|
+
|
|
28
|
+
`@dangao/nacos-client` **0.1.2+** automatically sends `namespaceId=` (empty value) when `namespaceId` is not configured, for both configuration and service discovery. Versions 0.1.1 and earlier omitted the parameter entirely, causing Nacos 3.x to return `code=20004`.
|
|
29
|
+
|
|
30
|
+
**Recommended**: omit `namespaceId` in client config for the public namespace:
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
nacos: {
|
|
34
|
+
client: {
|
|
35
|
+
serverList: ['http://localhost:8848'],
|
|
36
|
+
username: 'nacos',
|
|
37
|
+
password: 'nacos',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
For a custom namespace, pass the ID from the console (usually a UUID). If you patched `@dangao/nacos-client@0.1.1` with `bun patch`, remove `patchedDependencies` and the patch file after upgrading to 0.1.2+.
|
|
43
|
+
|
|
23
44
|
## Nacos Installation
|
|
24
45
|
|
|
25
46
|
### Docker Installation (Recommended)
|
|
@@ -48,7 +69,6 @@ app.registerModule(
|
|
|
48
69
|
nacos: {
|
|
49
70
|
client: {
|
|
50
71
|
serverList: ['http://localhost:8848'],
|
|
51
|
-
namespaceId: 'public',
|
|
52
72
|
username: 'nacos',
|
|
53
73
|
password: 'nacos',
|
|
54
74
|
},
|
|
@@ -125,7 +145,6 @@ app.registerModule(
|
|
|
125
145
|
nacos: {
|
|
126
146
|
client: {
|
|
127
147
|
serverList: ['http://localhost:8848'],
|
|
128
|
-
namespaceId: 'public',
|
|
129
148
|
username: 'nacos',
|
|
130
149
|
password: 'nacos',
|
|
131
150
|
},
|
|
@@ -197,7 +216,6 @@ import {
|
|
|
197
216
|
|
|
198
217
|
const instances = await serviceRegistry.getInstances('user-service', {
|
|
199
218
|
healthyOnly: true,
|
|
200
|
-
namespaceId: 'public',
|
|
201
219
|
});
|
|
202
220
|
|
|
203
221
|
// Watch for service instance changes
|
|
@@ -226,7 +244,6 @@ ConfigCenterModule.forRoot({
|
|
|
226
244
|
nacos: {
|
|
227
245
|
client: {
|
|
228
246
|
serverList: ['http://localhost:8848'],
|
|
229
|
-
namespaceId: 'public',
|
|
230
247
|
username: 'nacos',
|
|
231
248
|
password: 'nacos',
|
|
232
249
|
},
|
|
@@ -239,7 +256,6 @@ ServiceRegistryModule.forRoot({
|
|
|
239
256
|
nacos: {
|
|
240
257
|
client: {
|
|
241
258
|
serverList: ['http://localhost:8848'],
|
|
242
|
-
namespaceId: 'public',
|
|
243
259
|
username: 'nacos',
|
|
244
260
|
password: 'nacos',
|
|
245
261
|
},
|
|
@@ -337,6 +353,17 @@ await app.listen(3000);
|
|
|
337
353
|
- Check if configuration watch callback is correctly implemented
|
|
338
354
|
- Check logs to confirm if configuration changes are detected
|
|
339
355
|
|
|
356
|
+
### 6. Public Namespace Returns 20004
|
|
357
|
+
|
|
358
|
+
**Issue**: `getConfig` or service registration/discovery returns `code=20004` when `namespaceId` is not configured
|
|
359
|
+
|
|
360
|
+
**Cause**: Nacos 3.x requires `namespaceId=` (empty value) in requests; `@dangao/nacos-client` 0.1.1 and earlier omitted the parameter
|
|
361
|
+
|
|
362
|
+
**Solutions**:
|
|
363
|
+
- Upgrade `@dangao/nacos-client` to **0.1.2+** (pulled in via framework dependency, or pin explicitly in downstream projects)
|
|
364
|
+
- Remove any `bun patch` workaround
|
|
365
|
+
- Do not set `namespaceId` to the literal `"public"`; public maps to an empty string—omit the config instead
|
|
366
|
+
|
|
340
367
|
## Reference Resources
|
|
341
368
|
|
|
342
369
|
- [Nacos Official Documentation](https://nacos.io/docs/latest/)
|
|
@@ -22,6 +22,8 @@ Service registration and discovery provides core capabilities in microservice ar
|
|
|
22
22
|
- **Health Check**: Automatically update service health status based on health check results
|
|
23
23
|
- **Instance Watching**: Watch for service instance changes
|
|
24
24
|
|
|
25
|
+
> **Namespace**: Omit `namespaceId` for the Nacos public namespace. See [Nacos Integration - Namespace](./microservice-nacos.md#namespace).
|
|
26
|
+
|
|
25
27
|
## Quick Start
|
|
26
28
|
|
|
27
29
|
### 1. Register Service Registry Module
|
|
@@ -39,7 +41,6 @@ app.registerModule(
|
|
|
39
41
|
nacos: {
|
|
40
42
|
client: {
|
|
41
43
|
serverList: ['http://localhost:8848'],
|
|
42
|
-
namespaceId: 'public',
|
|
43
44
|
username: 'nacos',
|
|
44
45
|
password: 'nacos',
|
|
45
46
|
},
|
|
@@ -95,7 +96,6 @@ The simplest way is to use the `@ServiceRegistry` decorator:
|
|
|
95
96
|
region: 'us-east',
|
|
96
97
|
},
|
|
97
98
|
clusterName: 'default',
|
|
98
|
-
namespaceId: 'public',
|
|
99
99
|
groupName: 'DEFAULT_GROUP',
|
|
100
100
|
})
|
|
101
101
|
@Controller('/api/users')
|
|
@@ -113,7 +113,7 @@ class UserController {
|
|
|
113
113
|
- `healthy`: Initial health status
|
|
114
114
|
- `metadata`: Service metadata (version, region, etc.)
|
|
115
115
|
- `clusterName`: Cluster name
|
|
116
|
-
- `namespaceId`: Namespace
|
|
116
|
+
- `namespaceId`: Namespace ID; omit for public (empty string). See [Nacos Integration - Namespace](./microservice-nacos.md#namespace)
|
|
117
117
|
- `groupName`: Group name
|
|
118
118
|
|
|
119
119
|
### Manual Registration
|
|
@@ -182,7 +182,6 @@ import type { ServiceInstance } from '@dangao/bun-server';
|
|
|
182
182
|
class MyService {
|
|
183
183
|
@ServiceDiscovery('user-service', {
|
|
184
184
|
healthyOnly: true, // Only get healthy instances
|
|
185
|
-
namespaceId: 'public',
|
|
186
185
|
groupName: 'DEFAULT_GROUP',
|
|
187
186
|
})
|
|
188
187
|
public instances: ServiceInstance[] = [];
|
|
@@ -200,7 +199,6 @@ class MyService {
|
|
|
200
199
|
// Get service instance list
|
|
201
200
|
const instances = await serviceRegistry.getInstances('user-service', {
|
|
202
201
|
healthyOnly: true,
|
|
203
|
-
namespaceId: 'public',
|
|
204
202
|
groupName: 'DEFAULT_GROUP',
|
|
205
203
|
clusterName: 'default',
|
|
206
204
|
});
|
|
@@ -214,7 +212,6 @@ const unsubscribe = serviceRegistry.watchInstances(
|
|
|
214
212
|
updateLocalCache(newInstances);
|
|
215
213
|
},
|
|
216
214
|
{
|
|
217
|
-
namespaceId: 'public',
|
|
218
215
|
groupName: 'DEFAULT_GROUP',
|
|
219
216
|
},
|
|
220
217
|
);
|
package/docs/microservice.md
CHANGED
|
@@ -40,7 +40,6 @@ app.registerModule(
|
|
|
40
40
|
nacos: {
|
|
41
41
|
client: {
|
|
42
42
|
serverList: ['http://localhost:8848'],
|
|
43
|
-
namespaceId: 'public',
|
|
44
43
|
username: 'nacos',
|
|
45
44
|
password: 'nacos',
|
|
46
45
|
},
|
|
@@ -55,7 +54,6 @@ app.registerModule(
|
|
|
55
54
|
nacos: {
|
|
56
55
|
client: {
|
|
57
56
|
serverList: ['http://localhost:8848'],
|
|
58
|
-
namespaceId: 'public',
|
|
59
57
|
username: 'nacos',
|
|
60
58
|
password: 'nacos',
|
|
61
59
|
},
|
|
@@ -230,7 +228,6 @@ class MyService {
|
|
|
230
228
|
```typescript
|
|
231
229
|
const instances = await serviceRegistry.getInstances('user-service', {
|
|
232
230
|
healthyOnly: true,
|
|
233
|
-
namespaceId: 'public',
|
|
234
231
|
});
|
|
235
232
|
|
|
236
233
|
// Watch for service instance changes
|
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
- **配置优先级**:配置中心配置 > 环境变量 > 默认配置
|
|
22
22
|
- **配置监听**:监听配置变更,自动刷新应用配置
|
|
23
23
|
|
|
24
|
+
> **命名空间**:使用 Nacos public 命名空间(控制台默认)时,省略 `namespaceId` 即可。请勿设为字面量 `"public"`。详见 [Nacos 集成文档 - 命名空间](./microservice-nacos.md#命名空间)。
|
|
25
|
+
|
|
24
26
|
## 快速开始
|
|
25
27
|
|
|
26
28
|
### 1. 注册配置中心模块
|
|
@@ -37,7 +39,6 @@ app.registerModule(
|
|
|
37
39
|
nacos: {
|
|
38
40
|
client: {
|
|
39
41
|
serverList: ['http://localhost:8848'],
|
|
40
|
-
namespaceId: 'public',
|
|
41
42
|
username: 'nacos',
|
|
42
43
|
password: 'nacos',
|
|
43
44
|
},
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
## 目录
|
|
6
6
|
|
|
7
7
|
- [概述](#概述)
|
|
8
|
+
- [命名空间](#命名空间)
|
|
8
9
|
- [Nacos 安装](#nacos-安装)
|
|
9
10
|
- [配置中心集成](#配置中心集成)
|
|
10
11
|
- [服务注册中心集成](#服务注册中心集成)
|
|
@@ -20,6 +21,26 @@ Bun Server Framework 通过 `@dangao/nacos-client` 包提供 Nacos 3.X 支持,
|
|
|
20
21
|
- **服务发现**:服务实例查询和监听
|
|
21
22
|
- **Open API**:基于 Nacos 3.X Open API 实现
|
|
22
23
|
|
|
24
|
+
## 命名空间
|
|
25
|
+
|
|
26
|
+
Nacos 控制台默认命名空间显示为 **public**,但其 Open API 中的 ID 是**空字符串** `""`,不是字面量 `"public"`。
|
|
27
|
+
|
|
28
|
+
`@dangao/nacos-client` **0.1.2+** 在未配置 `namespaceId` 时会自动在请求中附带 `namespaceId=`(空值),适用于配置读取与服务发现。0.1.1 及更早版本会完全省略该参数,导致 Nacos 3.x 返回 `code=20004`。
|
|
29
|
+
|
|
30
|
+
**推荐做法**:使用 public 命名空间时,省略客户端配置中的 `namespaceId`:
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
nacos: {
|
|
34
|
+
client: {
|
|
35
|
+
serverList: ['http://localhost:8848'],
|
|
36
|
+
username: 'nacos',
|
|
37
|
+
password: 'nacos',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
自定义命名空间时传入控制台中的 ID(通常为 UUID)。若曾对 `@dangao/nacos-client@0.1.1` 使用 `bun patch`,升级至 0.1.2+ 后请移除 `patchedDependencies` 及对应 patch 文件。
|
|
43
|
+
|
|
23
44
|
## Nacos 安装
|
|
24
45
|
|
|
25
46
|
### Docker 安装(推荐)
|
|
@@ -48,7 +69,6 @@ app.registerModule(
|
|
|
48
69
|
nacos: {
|
|
49
70
|
client: {
|
|
50
71
|
serverList: ['http://localhost:8848'],
|
|
51
|
-
namespaceId: 'public',
|
|
52
72
|
username: 'nacos',
|
|
53
73
|
password: 'nacos',
|
|
54
74
|
},
|
|
@@ -125,7 +145,6 @@ app.registerModule(
|
|
|
125
145
|
nacos: {
|
|
126
146
|
client: {
|
|
127
147
|
serverList: ['http://localhost:8848'],
|
|
128
|
-
namespaceId: 'public',
|
|
129
148
|
username: 'nacos',
|
|
130
149
|
password: 'nacos',
|
|
131
150
|
},
|
|
@@ -197,7 +216,6 @@ import {
|
|
|
197
216
|
|
|
198
217
|
const instances = await serviceRegistry.getInstances('user-service', {
|
|
199
218
|
healthyOnly: true,
|
|
200
|
-
namespaceId: 'public',
|
|
201
219
|
});
|
|
202
220
|
|
|
203
221
|
// 监听服务实例变更
|
|
@@ -226,7 +244,6 @@ ConfigCenterModule.forRoot({
|
|
|
226
244
|
nacos: {
|
|
227
245
|
client: {
|
|
228
246
|
serverList: ['http://localhost:8848'],
|
|
229
|
-
namespaceId: 'public',
|
|
230
247
|
username: 'nacos',
|
|
231
248
|
password: 'nacos',
|
|
232
249
|
},
|
|
@@ -239,7 +256,6 @@ ServiceRegistryModule.forRoot({
|
|
|
239
256
|
nacos: {
|
|
240
257
|
client: {
|
|
241
258
|
serverList: ['http://localhost:8848'],
|
|
242
|
-
namespaceId: 'public',
|
|
243
259
|
username: 'nacos',
|
|
244
260
|
password: 'nacos',
|
|
245
261
|
},
|
|
@@ -337,6 +353,17 @@ await app.listen(3000);
|
|
|
337
353
|
- 检查配置监听回调是否正确实现
|
|
338
354
|
- 查看日志确认配置变更是否被检测到
|
|
339
355
|
|
|
356
|
+
### 6. public 命名空间返回 20004
|
|
357
|
+
|
|
358
|
+
**问题**:未配置 `namespaceId` 时,`getConfig` / 服务注册或发现返回 `code=20004`
|
|
359
|
+
|
|
360
|
+
**原因**:Nacos 3.x 要求请求携带 `namespaceId=`(空值);0.1.1 及更早的 `@dangao/nacos-client` 会完全省略该参数
|
|
361
|
+
|
|
362
|
+
**解决方案**:
|
|
363
|
+
- 升级 `@dangao/nacos-client` 至 **0.1.2+**(框架依赖会自动带入,也可在下游项目中显式升级)
|
|
364
|
+
- 移除 `bun patch`(如有)
|
|
365
|
+
- 不要将 `namespaceId` 设为字面量 `"public"`;public 对应空字符串,推荐直接省略配置
|
|
366
|
+
|
|
340
367
|
## 参考资源
|
|
341
368
|
|
|
342
369
|
- [Nacos 官方文档](https://nacos.io/docs/latest/)
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
- **健康检查**:自动根据健康检查状态更新服务健康状态
|
|
23
23
|
- **实例监听**:监听服务实例变更
|
|
24
24
|
|
|
25
|
+
> **命名空间**:使用 Nacos public 命名空间时省略 `namespaceId`。详见 [Nacos 集成文档 - 命名空间](./microservice-nacos.md#命名空间)。
|
|
26
|
+
|
|
25
27
|
## 快速开始
|
|
26
28
|
|
|
27
29
|
### 1. 注册服务注册中心模块
|
|
@@ -39,7 +41,6 @@ app.registerModule(
|
|
|
39
41
|
nacos: {
|
|
40
42
|
client: {
|
|
41
43
|
serverList: ['http://localhost:8848'],
|
|
42
|
-
namespaceId: 'public',
|
|
43
44
|
username: 'nacos',
|
|
44
45
|
password: 'nacos',
|
|
45
46
|
},
|
|
@@ -94,7 +95,6 @@ await app.listen(3000);
|
|
|
94
95
|
region: 'us-east',
|
|
95
96
|
},
|
|
96
97
|
clusterName: 'default',
|
|
97
|
-
namespaceId: 'public',
|
|
98
98
|
groupName: 'DEFAULT_GROUP',
|
|
99
99
|
})
|
|
100
100
|
@Controller('/api/users')
|
|
@@ -112,7 +112,7 @@ class UserController {
|
|
|
112
112
|
- `healthy`:初始健康状态
|
|
113
113
|
- `metadata`:服务元数据(版本、区域等)
|
|
114
114
|
- `clusterName`:集群名
|
|
115
|
-
- `namespaceId`:命名空间
|
|
115
|
+
- `namespaceId`:命名空间 ID;省略表示 public(空字符串)。详见 [Nacos 集成文档 - 命名空间](./microservice-nacos.md#命名空间)
|
|
116
116
|
- `groupName`:分组名
|
|
117
117
|
|
|
118
118
|
### 手动注册
|
|
@@ -181,7 +181,6 @@ import type { ServiceInstance } from '@dangao/bun-server';
|
|
|
181
181
|
class MyService {
|
|
182
182
|
@ServiceDiscovery('user-service', {
|
|
183
183
|
healthyOnly: true, // 只获取健康实例
|
|
184
|
-
namespaceId: 'public',
|
|
185
184
|
groupName: 'DEFAULT_GROUP',
|
|
186
185
|
})
|
|
187
186
|
public instances: ServiceInstance[] = [];
|
|
@@ -199,7 +198,6 @@ class MyService {
|
|
|
199
198
|
// 获取服务实例列表
|
|
200
199
|
const instances = await serviceRegistry.getInstances('user-service', {
|
|
201
200
|
healthyOnly: true,
|
|
202
|
-
namespaceId: 'public',
|
|
203
201
|
groupName: 'DEFAULT_GROUP',
|
|
204
202
|
clusterName: 'default',
|
|
205
203
|
});
|
|
@@ -213,7 +211,6 @@ const unsubscribe = serviceRegistry.watchInstances(
|
|
|
213
211
|
updateLocalCache(newInstances);
|
|
214
212
|
},
|
|
215
213
|
{
|
|
216
|
-
namespaceId: 'public',
|
|
217
214
|
groupName: 'DEFAULT_GROUP',
|
|
218
215
|
},
|
|
219
216
|
);
|
package/docs/zh/microservice.md
CHANGED
|
@@ -40,7 +40,6 @@ app.registerModule(
|
|
|
40
40
|
nacos: {
|
|
41
41
|
client: {
|
|
42
42
|
serverList: ['http://localhost:8848'],
|
|
43
|
-
namespaceId: 'public',
|
|
44
43
|
username: 'nacos',
|
|
45
44
|
password: 'nacos',
|
|
46
45
|
},
|
|
@@ -55,7 +54,6 @@ app.registerModule(
|
|
|
55
54
|
nacos: {
|
|
56
55
|
client: {
|
|
57
56
|
serverList: ['http://localhost:8848'],
|
|
58
|
-
namespaceId: 'public',
|
|
59
57
|
username: 'nacos',
|
|
60
58
|
password: 'nacos',
|
|
61
59
|
},
|
|
@@ -230,7 +228,6 @@ class MyService {
|
|
|
230
228
|
```typescript
|
|
231
229
|
const instances = await serviceRegistry.getInstances('user-service', {
|
|
232
230
|
healthyOnly: true,
|
|
233
|
-
namespaceId: 'public',
|
|
234
231
|
});
|
|
235
232
|
|
|
236
233
|
// 监听服务实例变更
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dangao/bun-server",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
81
|
"@dangao/logsmith": "0.2.0",
|
|
82
|
-
"@dangao/nacos-client": "0.1.
|
|
82
|
+
"@dangao/nacos-client": "0.1.2",
|
|
83
83
|
"json5": "^2.2.3",
|
|
84
84
|
"jsonc-parser": "^3.3.1",
|
|
85
85
|
"marked": "^18.0.0",
|