@lark-apaas/devtool-kits 0.1.0-alpha.9 → 1.0.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 +6 -0
- package/dist/error.html +285 -0
- package/dist/index.cjs +343 -221
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +43 -1
- package/dist/index.d.ts +43 -1
- package/dist/index.js +336 -215
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
1
2
|
import { Router, RequestHandler, Application } from 'express';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -13,6 +14,47 @@ type PostprocessStats = {
|
|
|
13
14
|
};
|
|
14
15
|
declare function postprocessDrizzleSchema(targetPath: string): PostprocessStats | undefined;
|
|
15
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Proxy Error Handler 选项
|
|
19
|
+
*/
|
|
20
|
+
interface ProxyErrorOptions {
|
|
21
|
+
/** 日志目录路径 */
|
|
22
|
+
logDir?: string;
|
|
23
|
+
/** 读取最近多少条错误日志 */
|
|
24
|
+
maxErrorLogs?: number;
|
|
25
|
+
/** 日志文件名(默认为 server.log) */
|
|
26
|
+
logFileName?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* HTTP Proxy 错误处理器
|
|
30
|
+
* 用于 http-proxy 的 onError 回调
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
35
|
+
* import { handleDevProxyError } from '@lark-apaas/devtool-kits';
|
|
36
|
+
*
|
|
37
|
+
* // 基础用法
|
|
38
|
+
* const proxy = createProxyMiddleware({
|
|
39
|
+
* target: 'http://localhost:3000',
|
|
40
|
+
* onError: handleDevProxyError
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // 自定义配置
|
|
44
|
+
* const proxy = createProxyMiddleware({
|
|
45
|
+
* target: 'http://localhost:3000',
|
|
46
|
+
* onError: (err, req, res) => {
|
|
47
|
+
* handleDevProxyError(err, req, res, {
|
|
48
|
+
* logDir: './logs',
|
|
49
|
+
* maxErrorLogs: 50,
|
|
50
|
+
* logFileName: 'server.log'
|
|
51
|
+
* });
|
|
52
|
+
* }
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
declare function handleDevProxyError(err: Error, _req: IncomingMessage, res: ServerResponse, options?: ProxyErrorOptions): void;
|
|
57
|
+
|
|
16
58
|
/**
|
|
17
59
|
* Shared context passed to all middlewares
|
|
18
60
|
*/
|
|
@@ -188,4 +230,4 @@ declare function createCollectLogsMiddleware(options?: DevLogsMiddlewareOptions)
|
|
|
188
230
|
*/
|
|
189
231
|
declare function registerMiddlewares(server: ExpressApp | ViteMiddleware, middlewares: Middleware[], options?: Partial<MiddlewareContext>): Promise<void>;
|
|
190
232
|
|
|
191
|
-
export { type GlobalMiddleware, type Middleware, type MiddlewareContext, type RouteInfo, type RouteMiddleware, createCollectLogsMiddleware, createDevLogsMiddleware, createOpenapiMiddleware, normalizeBasePath, postprocessDrizzleSchema, registerMiddlewares };
|
|
233
|
+
export { type GlobalMiddleware, type Middleware, type MiddlewareContext, type RouteInfo, type RouteMiddleware, createCollectLogsMiddleware, createDevLogsMiddleware, createOpenapiMiddleware, handleDevProxyError, normalizeBasePath, postprocessDrizzleSchema, registerMiddlewares };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
1
2
|
import { Router, RequestHandler, Application } from 'express';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -13,6 +14,47 @@ type PostprocessStats = {
|
|
|
13
14
|
};
|
|
14
15
|
declare function postprocessDrizzleSchema(targetPath: string): PostprocessStats | undefined;
|
|
15
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Proxy Error Handler 选项
|
|
19
|
+
*/
|
|
20
|
+
interface ProxyErrorOptions {
|
|
21
|
+
/** 日志目录路径 */
|
|
22
|
+
logDir?: string;
|
|
23
|
+
/** 读取最近多少条错误日志 */
|
|
24
|
+
maxErrorLogs?: number;
|
|
25
|
+
/** 日志文件名(默认为 server.log) */
|
|
26
|
+
logFileName?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* HTTP Proxy 错误处理器
|
|
30
|
+
* 用于 http-proxy 的 onError 回调
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
35
|
+
* import { handleDevProxyError } from '@lark-apaas/devtool-kits';
|
|
36
|
+
*
|
|
37
|
+
* // 基础用法
|
|
38
|
+
* const proxy = createProxyMiddleware({
|
|
39
|
+
* target: 'http://localhost:3000',
|
|
40
|
+
* onError: handleDevProxyError
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // 自定义配置
|
|
44
|
+
* const proxy = createProxyMiddleware({
|
|
45
|
+
* target: 'http://localhost:3000',
|
|
46
|
+
* onError: (err, req, res) => {
|
|
47
|
+
* handleDevProxyError(err, req, res, {
|
|
48
|
+
* logDir: './logs',
|
|
49
|
+
* maxErrorLogs: 50,
|
|
50
|
+
* logFileName: 'server.log'
|
|
51
|
+
* });
|
|
52
|
+
* }
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
declare function handleDevProxyError(err: Error, _req: IncomingMessage, res: ServerResponse, options?: ProxyErrorOptions): void;
|
|
57
|
+
|
|
16
58
|
/**
|
|
17
59
|
* Shared context passed to all middlewares
|
|
18
60
|
*/
|
|
@@ -188,4 +230,4 @@ declare function createCollectLogsMiddleware(options?: DevLogsMiddlewareOptions)
|
|
|
188
230
|
*/
|
|
189
231
|
declare function registerMiddlewares(server: ExpressApp | ViteMiddleware, middlewares: Middleware[], options?: Partial<MiddlewareContext>): Promise<void>;
|
|
190
232
|
|
|
191
|
-
export { type GlobalMiddleware, type Middleware, type MiddlewareContext, type RouteInfo, type RouteMiddleware, createCollectLogsMiddleware, createDevLogsMiddleware, createOpenapiMiddleware, normalizeBasePath, postprocessDrizzleSchema, registerMiddlewares };
|
|
233
|
+
export { type GlobalMiddleware, type Middleware, type MiddlewareContext, type RouteInfo, type RouteMiddleware, createCollectLogsMiddleware, createDevLogsMiddleware, createOpenapiMiddleware, handleDevProxyError, normalizeBasePath, postprocessDrizzleSchema, registerMiddlewares };
|