Make starter project delivery-ready
This commit is contained in:
1 parent
5b300dee0d
commit
d7bfde754b
22 files changed
+695
-71
No files matched your search
@@ -166,6 +166,11 @@ const sources = defineDataSources({
|
||||
字段说明:
|
||||
|
||||
- `url`: 请求地址。
|
||||
- `baseUrl`: API 基础地址,建议来自 `.env`。
|
||||
- `query`: 查询参数。
|
||||
- `headers`: 静态 header 或返回 header 的函数。
|
||||
- `authToken`: token 字符串或返回 token 的函数,会自动写入 `Authorization: Bearer <token>`。
|
||||
- `timeoutMs`: 超时时间。
|
||||
- `init`: `fetch` 的 RequestInit 参数。
|
||||
- `intervalMs`: 轮询间隔,不传则只请求一次。
|
||||
- `immediate`: 是否立即请求,默认 `true`。
|
||||
@@ -186,6 +191,8 @@ const sources = defineDataSources({
|
||||
url: 'ws://localhost:3000/ws/alerts',
|
||||
mode: 'append',
|
||||
maxItems: 20,
|
||||
reconnect: { enabled: true, maxRetries: 10, delayMs: 3000 },
|
||||
heartbeat: { message: 'ping', intervalMs: 30000 },
|
||||
transform: (raw) => ({
|
||||
time: raw.time,
|
||||
message: raw.message
|
||||
@@ -200,6 +207,8 @@ const sources = defineDataSources({
|
||||
- `protocols`: 可选 WebSocket protocols。
|
||||
- `mode`: `replace` 或 `append`,默认 `replace`。
|
||||
- `maxItems`: `append` 模式最多保留多少条。
|
||||
- `reconnect`: 断线重连设置。
|
||||
- `heartbeat`: 心跳消息设置。
|
||||
- `transform`: 单条消息的清洗函数。
|
||||
|
||||
WebSocket 消息如果是字符串,会优先尝试 `JSON.parse`。如果不是 JSON,会把原始字符串传给 `transform`。
|
||||
|
||||
Reference in new issue
Block a user