@lark-apaas/devtool-kits 1.2.15 → 1.2.16-beta.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/README.md +43 -0
- package/dist/index.cjs +235 -262
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +43 -20
- package/dist/index.d.ts +43 -20
- package/dist/index.js +204 -236
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/error.html +0 -195
package/README.md
CHANGED
|
@@ -92,6 +92,17 @@ import {
|
|
|
92
92
|
} from '@apaas/fullstack-toolkits';
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
+
### 兼容工具函数 (Compat)
|
|
96
|
+
```typescript
|
|
97
|
+
import {
|
|
98
|
+
sendJson, // 发送 JSON 响应(兼容 Express/Connect)
|
|
99
|
+
sendError, // 发送错误响应
|
|
100
|
+
sendSuccess, // 发送成功响应
|
|
101
|
+
getQuery, // 获取所有查询参数
|
|
102
|
+
getQueryParam, // 获取单个查询参数
|
|
103
|
+
} from '@apaas/fullstack-toolkits';
|
|
104
|
+
```
|
|
105
|
+
|
|
95
106
|
### 类型定义 (Types)
|
|
96
107
|
```typescript
|
|
97
108
|
import type {
|
|
@@ -171,6 +182,38 @@ export default {
|
|
|
171
182
|
- 全局中间件应放在路由中间件之前
|
|
172
183
|
- 路由中间件仅处理匹配其挂载路径的请求
|
|
173
184
|
|
|
185
|
+
### Vite/Connect 兼容性
|
|
186
|
+
|
|
187
|
+
本工具包原生支持 Vite 开发服务器。`registerMiddlewares` 会自动检测 Vite/Connect 环境,并添加必要的 Express API 兼容层:
|
|
188
|
+
|
|
189
|
+
- `res.status()` - 设置响应状态码
|
|
190
|
+
- `res.json()` - 发送 JSON 响应
|
|
191
|
+
- `res.send()` - 发送响应
|
|
192
|
+
- `req.query` - 解析后的查询参数
|
|
193
|
+
|
|
194
|
+
这意味着您可以直接在 Vite 中使用本工具包,无需额外配置。
|
|
195
|
+
|
|
196
|
+
**兼容工具函数(可选):**
|
|
197
|
+
|
|
198
|
+
如果您正在编写自定义中间件并希望同时支持 Express 和 Vite,可以使用导出的兼容工具函数:
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
import { sendJson, sendError, sendSuccess, getQuery, getQueryParam } from '@lark-apaas/devtool-kits';
|
|
202
|
+
|
|
203
|
+
// 发送 JSON 响应(自动检测 Express/Connect)
|
|
204
|
+
sendJson(res, { data: 'value' }, 200);
|
|
205
|
+
|
|
206
|
+
// 发送错误响应
|
|
207
|
+
sendError(res, 'Not found', error, 404);
|
|
208
|
+
|
|
209
|
+
// 发送成功响应
|
|
210
|
+
sendSuccess(res, { id: 123 });
|
|
211
|
+
|
|
212
|
+
// 获取查询参数(自动解析 URL 或使用 req.query)
|
|
213
|
+
const query = getQuery(req);
|
|
214
|
+
const page = getQueryParam(req, 'page');
|
|
215
|
+
```
|
|
216
|
+
|
|
174
217
|
## 中间件详细说明
|
|
175
218
|
### Dev Logs 中间件
|
|
176
219
|
|