@gylautorun/dev-proxy-cookie 1.0.1 → 1.0.3
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 +212 -236
- package/dist/index.d.mts +304 -67
- package/dist/index.d.ts +304 -67
- package/dist/index.js +314 -173
- package/dist/index.min.js +4 -4
- package/dist/index.min.mjs +4 -4
- package/dist/index.mjs +313 -168
- package/package.json +1 -1
- package/src/index.ts +13 -0
- package/src/proxy/apply-dev-cookie-header.ts +35 -5
- package/src/proxy/core.ts +198 -12
- package/src/proxy/index.ts +8 -3
- package/src/proxy/vite-middleware-plugin.ts +177 -0
- package/src/proxy/vue-proxy-config.ts +98 -18
- package/src/utils/cookie-reader.ts +74 -3
- package/src/utils/cookie-watcher.ts +50 -1
- package/src/utils/env-detector.ts +9 -2
- package/src/utils/index.ts +7 -0
- package/src/proxy/vite-adapter.ts +0 -98
- package/src/proxy/vite-cookie-plugin.ts +0 -94
- package/src/proxy/vite-plugin.ts +0 -66
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import * as net from 'net';
|
|
2
2
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
-
import { ViteDevServer
|
|
3
|
+
import { ViteDevServer } from 'vite';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* 错误回调函数类型
|
|
7
|
+
* @param err - 错误对象
|
|
8
|
+
* @param req - 请求对象
|
|
9
|
+
* @param res - 响应对象或 Socket
|
|
10
|
+
*/
|
|
5
11
|
type ErrorCallback = (err: Error, req: IncomingMessage, res: ServerResponse | net.Socket) => void;
|
|
6
12
|
interface ProxyHooks {
|
|
7
13
|
onProxyReq?: (proxyReq: any, req: IncomingMessage, res: ServerResponse) => void;
|
|
@@ -16,6 +22,12 @@ interface AutoProxyCookieOptions {
|
|
|
16
22
|
autoRestart?: boolean;
|
|
17
23
|
restartMarkerFile?: string;
|
|
18
24
|
proxyMap?: Record<string, string>;
|
|
25
|
+
/**
|
|
26
|
+
* 需要代理的路径前缀列表(默认代理到 target)
|
|
27
|
+
* 例如: ['/api', '/digital-platform']
|
|
28
|
+
* 如果请求路径匹配这些前缀之一,将被代理到 target
|
|
29
|
+
*/
|
|
30
|
+
proxyPaths?: string[];
|
|
19
31
|
ignorePaths?: string[];
|
|
20
32
|
ws?: boolean;
|
|
21
33
|
changeOrigin?: boolean;
|
|
@@ -34,6 +46,15 @@ interface AutoProxyCookieOptions {
|
|
|
34
46
|
[header: string]: string;
|
|
35
47
|
};
|
|
36
48
|
hooks?: ProxyHooks;
|
|
49
|
+
/**
|
|
50
|
+
* 是否启用文件监听
|
|
51
|
+
* - 'auto': 自动(如果 isDev 为 true,则启用监听)
|
|
52
|
+
* - true: 强制启用监听
|
|
53
|
+
* - false: 禁用监听
|
|
54
|
+
*
|
|
55
|
+
* 默认值: 'auto'
|
|
56
|
+
*/
|
|
57
|
+
watch?: 'auto' | boolean;
|
|
37
58
|
/**
|
|
38
59
|
* 是否为开发环境(优先级最高)
|
|
39
60
|
* 设置此参数后,将直接决定是否启用文件监听:
|
|
@@ -43,68 +64,171 @@ interface AutoProxyCookieOptions {
|
|
|
43
64
|
* 使用示例: isDev: process.env.NODE_ENV === 'development'
|
|
44
65
|
*/
|
|
45
66
|
isDev?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* 是否使用 Cookie 文件中的 Cookie 注入到请求中
|
|
69
|
+
* - true: 使用文件中的 Cookie(默认)
|
|
70
|
+
* - false: 不注入 Cookie,使用浏览器发送的 Cookie
|
|
71
|
+
*
|
|
72
|
+
* 当使用账号密码登录时,设置为 false,避免覆盖浏览器的登录 Cookie
|
|
73
|
+
*/
|
|
74
|
+
useCookie?: boolean;
|
|
46
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* 自动代理 Cookie 类
|
|
78
|
+
*
|
|
79
|
+
* 提供完整的开发环境代理解决方案,支持 HTTP 和 WebSocket 代理,
|
|
80
|
+
* 自动从文件读取 Cookie 并注入到代理请求中。
|
|
81
|
+
*/
|
|
47
82
|
declare class AutoProxyCookie {
|
|
83
|
+
/** 合并后的配置选项 */
|
|
48
84
|
private options;
|
|
85
|
+
/** 当前 Cookie 值 */
|
|
49
86
|
private currentCookie;
|
|
87
|
+
/** Vite 开发服务器实例 */
|
|
50
88
|
private server;
|
|
89
|
+
/** HTTP 代理服务器实例 */
|
|
51
90
|
private proxyServer;
|
|
91
|
+
/** Cookie 文件监听器 */
|
|
52
92
|
private watcher;
|
|
93
|
+
/** Cookie 文件读取器 */
|
|
53
94
|
private cookieReader;
|
|
95
|
+
/**
|
|
96
|
+
* 构造函数
|
|
97
|
+
* @param options - 配置选项
|
|
98
|
+
*/
|
|
54
99
|
constructor(options: AutoProxyCookieOptions);
|
|
100
|
+
/**
|
|
101
|
+
* Cookie 变化处理函数
|
|
102
|
+
* @param newCookie - 新的 Cookie 值
|
|
103
|
+
*/
|
|
55
104
|
private handleCookieChange;
|
|
105
|
+
/**
|
|
106
|
+
* 根据请求路径获取代理目标 URL
|
|
107
|
+
* @param req - HTTP 请求对象
|
|
108
|
+
* @returns 代理目标 URL
|
|
109
|
+
*/
|
|
56
110
|
private getProxyUrl;
|
|
111
|
+
/**
|
|
112
|
+
* 判断路径是否应该被忽略(不代理)
|
|
113
|
+
* @param pathname - 请求路径
|
|
114
|
+
* @returns 是否忽略
|
|
115
|
+
*/
|
|
57
116
|
private isIgnoredPath;
|
|
117
|
+
/**
|
|
118
|
+
* 日志输出函数
|
|
119
|
+
* @param level - 日志级别
|
|
120
|
+
* @param args - 日志参数
|
|
121
|
+
*/
|
|
58
122
|
private log;
|
|
123
|
+
/**
|
|
124
|
+
* 创建代理服务器配置选项
|
|
125
|
+
* @param target - 代理目标地址
|
|
126
|
+
* @returns 代理服务器配置
|
|
127
|
+
*/
|
|
59
128
|
private createProxyOptions;
|
|
129
|
+
/**
|
|
130
|
+
* 代理请求处理函数
|
|
131
|
+
* @param proxyReq - 代理请求对象
|
|
132
|
+
* @param req - 原始请求对象
|
|
133
|
+
* @param res - 响应对象
|
|
134
|
+
* @param _options - 服务器选项
|
|
135
|
+
*/
|
|
60
136
|
private handleOnProxyReq;
|
|
137
|
+
/**
|
|
138
|
+
* 代理响应处理函数
|
|
139
|
+
* @param proxyRes - 代理响应对象
|
|
140
|
+
* @param req - 原始请求对象
|
|
141
|
+
* @param res - 响应对象
|
|
142
|
+
*/
|
|
61
143
|
private handleOnProxyRes;
|
|
144
|
+
/**
|
|
145
|
+
* HTTP 代理错误处理函数
|
|
146
|
+
* @param err - 错误对象
|
|
147
|
+
* @param req - 请求对象
|
|
148
|
+
* @param res - 响应对象或 Socket
|
|
149
|
+
*/
|
|
62
150
|
private handleOnError;
|
|
151
|
+
/**
|
|
152
|
+
* WebSocket 代理错误处理函数
|
|
153
|
+
* @param err - 错误对象
|
|
154
|
+
* @param req - 请求对象
|
|
155
|
+
* @param socket - WebSocket 连接的 Socket
|
|
156
|
+
*/
|
|
63
157
|
private handleOnWsError;
|
|
158
|
+
/**
|
|
159
|
+
* 初始化代理中间件
|
|
160
|
+
* @param server - Vite 开发服务器实例
|
|
161
|
+
*/
|
|
64
162
|
setup(server: ViteDevServer): Promise<void>;
|
|
163
|
+
/**
|
|
164
|
+
* 启动 Cookie 文件监听
|
|
165
|
+
*/
|
|
65
166
|
private startFileWatch;
|
|
167
|
+
/**
|
|
168
|
+
* 停止代理服务
|
|
169
|
+
*/
|
|
66
170
|
stop(): void;
|
|
171
|
+
/**
|
|
172
|
+
* 获取当前 Cookie 值
|
|
173
|
+
* @returns 当前 Cookie 字符串
|
|
174
|
+
*/
|
|
67
175
|
getCurrentCookie(): string;
|
|
68
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* 创建 AutoProxyCookie 实例
|
|
179
|
+
* @param options - 配置选项
|
|
180
|
+
* @returns AutoProxyCookie 实例
|
|
181
|
+
*/
|
|
69
182
|
declare function createAutoProxyCookie(options: AutoProxyCookieOptions): AutoProxyCookie;
|
|
70
183
|
|
|
71
|
-
|
|
72
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Vite 中间件代理 Cookie 插件配置选项
|
|
186
|
+
*/
|
|
187
|
+
interface ViteMiddlewareProxyOptions {
|
|
188
|
+
/** Cookie 文件路径 */
|
|
189
|
+
cookieFile: string;
|
|
190
|
+
/** 默认代理目标地址 */
|
|
191
|
+
target: string;
|
|
192
|
+
/** 是否启用调试日志 */
|
|
193
|
+
debug?: boolean;
|
|
73
194
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* -
|
|
77
|
-
* - false: 禁用监听(生产模式)
|
|
195
|
+
* 是否使用 Cookie 文件中的 Cookie 注入到请求中
|
|
196
|
+
* - true: 使用文件中的 Cookie(默认)
|
|
197
|
+
* - false: 不注入 Cookie,使用浏览器发送的 Cookie
|
|
78
198
|
*
|
|
79
|
-
*
|
|
199
|
+
* 当使用账号密码登录时,设置为 false,避免覆盖浏览器的登录 Cookie
|
|
80
200
|
*/
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
declare function viteAutoProxyCookie(options: ViteAutoProxyCookiePluginOptions): Plugin;
|
|
84
|
-
|
|
85
|
-
interface ViteDevProxyCookieOptions {
|
|
86
|
-
cookieFile: string;
|
|
87
|
-
debug?: boolean;
|
|
88
|
-
onCookieChange?: (cookie: string) => void;
|
|
201
|
+
useCookie?: boolean;
|
|
89
202
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* - false: 从不监听
|
|
93
|
-
* - 'auto': 根据环境自动判断(默认)
|
|
94
|
-
* @default 'auto'
|
|
203
|
+
* 代理路径映射表
|
|
204
|
+
* 键:路径前缀,值:代理目标地址
|
|
95
205
|
*/
|
|
96
|
-
|
|
206
|
+
proxyMap?: Record<string, string>;
|
|
97
207
|
/**
|
|
98
|
-
*
|
|
99
|
-
* 设置此参数后,将直接决定是否启用文件监听:
|
|
100
|
-
* - true: 启用监听(开发模式)
|
|
101
|
-
* - false: 禁用监听(生产模式)
|
|
102
|
-
*
|
|
103
|
-
* 使用示例: isDev: process.env.NODE_ENV === 'development'
|
|
208
|
+
* 需要代理的路径前缀列表(使用默认 target)
|
|
104
209
|
*/
|
|
105
|
-
|
|
210
|
+
proxyPaths?: string[];
|
|
211
|
+
/**
|
|
212
|
+
* 需要忽略的路径前缀列表(不代理)
|
|
213
|
+
*/
|
|
214
|
+
ignorePaths?: string[];
|
|
106
215
|
}
|
|
107
|
-
|
|
216
|
+
/**
|
|
217
|
+
* 创建 Vite 中间件代理 Cookie 插件
|
|
218
|
+
*
|
|
219
|
+
* @param options - 插件配置选项
|
|
220
|
+
* @returns Vite 插件对象
|
|
221
|
+
*/
|
|
222
|
+
declare function viteMiddlewareProxy(options: ViteMiddlewareProxyOptions): any;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Vue CLI 代理配置模块
|
|
226
|
+
*
|
|
227
|
+
* 提供 Vue CLI 开发服务器的代理配置功能,支持从文件读取 Cookie 并注入代理请求。
|
|
228
|
+
* 核心函数包括 createFileCookieGetter 和 createVueProxyConfig。
|
|
229
|
+
*
|
|
230
|
+
* @module vue-proxy-config
|
|
231
|
+
*/
|
|
108
232
|
|
|
109
233
|
/** Options for {@link createFileCookieGetter}. */
|
|
110
234
|
interface CreateFileCookieGetterOptions {
|
|
@@ -136,105 +260,218 @@ interface CreateFileCookieGetterOptions {
|
|
|
136
260
|
*/
|
|
137
261
|
isDev?: boolean;
|
|
138
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* Vue 代理配置选项
|
|
265
|
+
*/
|
|
139
266
|
interface VueProxyConfigOptions {
|
|
267
|
+
/** Cookie 获取函数 */
|
|
140
268
|
getCookie?: () => string;
|
|
269
|
+
/** 是否输出调试日志 */
|
|
141
270
|
debug?: boolean;
|
|
271
|
+
/**
|
|
272
|
+
* 是否使用 Cookie 文件中的 Cookie 注入到请求中
|
|
273
|
+
* - true: 使用文件中的 Cookie(默认)
|
|
274
|
+
* - false: 不注入 Cookie,使用浏览器发送的 Cookie
|
|
275
|
+
*
|
|
276
|
+
* 当使用账号密码登录时,设置为 false,避免覆盖浏览器的登录 Cookie
|
|
277
|
+
*/
|
|
278
|
+
useCookie?: boolean;
|
|
279
|
+
/** 自定义请求头 */
|
|
142
280
|
headers?: Record<string, string>;
|
|
281
|
+
/** 是否启用 WebSocket 代理 */
|
|
143
282
|
ws?: boolean;
|
|
283
|
+
/** 是否修改请求头中的 Origin */
|
|
144
284
|
changeOrigin?: boolean;
|
|
285
|
+
/** 是否验证 SSL 证书 */
|
|
145
286
|
secure?: boolean;
|
|
287
|
+
/** 错误回调函数 */
|
|
146
288
|
onError?: (err: Error) => void;
|
|
147
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* Vue CLI 代理配置接口
|
|
292
|
+
*
|
|
293
|
+
* 符合 Vue CLI 代理配置格式的对象结构
|
|
294
|
+
*/
|
|
148
295
|
interface ProxyConfig {
|
|
296
|
+
/** 是否启用 WebSocket 代理 */
|
|
149
297
|
ws: boolean;
|
|
298
|
+
/** 代理目标地址 */
|
|
150
299
|
target: string;
|
|
300
|
+
/** 是否修改请求头中的 Origin */
|
|
151
301
|
changeOrigin: boolean;
|
|
302
|
+
/** 是否验证 SSL 证书 */
|
|
152
303
|
secure: boolean;
|
|
304
|
+
/** 代理请求前的回调函数 */
|
|
153
305
|
onProxyReq: (proxyReq: any, req: IncomingMessage) => void;
|
|
306
|
+
/** 代理响应后的回调函数(可选) */
|
|
154
307
|
onProxyRes?: (proxyRes: any, req: IncomingMessage) => void;
|
|
308
|
+
/** 错误处理回调函数 */
|
|
155
309
|
onError: (err: Error) => void;
|
|
310
|
+
/** 自定义请求头 */
|
|
156
311
|
headers?: Record<string, string>;
|
|
157
312
|
}
|
|
313
|
+
/**
|
|
314
|
+
* 创建 Vue CLI 代理配置
|
|
315
|
+
*
|
|
316
|
+
* @param target - 代理目标地址
|
|
317
|
+
* @param options - 配置选项
|
|
318
|
+
* @returns Vue CLI 代理配置对象
|
|
319
|
+
*/
|
|
158
320
|
declare function createVueProxyConfig(target: string, options?: VueProxyConfigOptions): ProxyConfig;
|
|
321
|
+
/**
|
|
322
|
+
* 创建文件 Cookie 获取器
|
|
323
|
+
*
|
|
324
|
+
* 从指定文件读取 Cookie 值,支持文件监听功能。
|
|
325
|
+
*
|
|
326
|
+
* @param cookieFile - Cookie 文件路径
|
|
327
|
+
* @param options - 配置选项
|
|
328
|
+
* @returns Cookie 获取函数
|
|
329
|
+
*/
|
|
159
330
|
declare function createFileCookieGetter(cookieFile: string, options?: CreateFileCookieGetterOptions): () => string;
|
|
331
|
+
/**
|
|
332
|
+
* 自动代理配置选项
|
|
333
|
+
*/
|
|
160
334
|
interface AutoProxyConfigOptions extends VueProxyConfigOptions {
|
|
335
|
+
/** 代理目标地址 */
|
|
161
336
|
target: string;
|
|
337
|
+
/** 忽略的路径列表(不代理这些路径) */
|
|
162
338
|
ignorePaths?: string[];
|
|
339
|
+
/** 包含的路径列表(只代理这些路径) */
|
|
163
340
|
includePaths?: string[];
|
|
341
|
+
/** 额外的代理配置 */
|
|
164
342
|
additionalProxies?: Record<string, string>;
|
|
165
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* 创建自动代理配置
|
|
346
|
+
*
|
|
347
|
+
* 根据配置自动生成 Vue CLI 代理配置对象,支持忽略路径和包含路径两种模式。
|
|
348
|
+
*
|
|
349
|
+
* @param options - 配置选项
|
|
350
|
+
* @returns Vue CLI 代理配置对象映射
|
|
351
|
+
*/
|
|
166
352
|
declare function createAutoProxyConfig(options: AutoProxyConfigOptions): Record<string, ProxyConfig>;
|
|
167
353
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
debug?: boolean;
|
|
172
|
-
autoRestart?: boolean;
|
|
173
|
-
restartMarkerFile?: string;
|
|
174
|
-
proxyMap?: Record<string, string>;
|
|
175
|
-
ignorePaths?: string[];
|
|
176
|
-
includePaths?: string[];
|
|
177
|
-
onCookieChange?: (cookie: string) => void;
|
|
178
|
-
mode?: 'auto' | 'proxy' | 'cookie';
|
|
179
|
-
/**
|
|
180
|
-
* 是否监听文件变化
|
|
181
|
-
* - true: 始终监听
|
|
182
|
-
* - false: 从不监听
|
|
183
|
-
* - 'auto': 根据环境自动判断(默认)
|
|
184
|
-
* @default 'auto'
|
|
185
|
-
*/
|
|
186
|
-
watch?: boolean | 'auto';
|
|
187
|
-
/**
|
|
188
|
-
* 是否为开发环境(优先级最高)
|
|
189
|
-
* 设置此参数后,将直接决定是否启用文件监听:
|
|
190
|
-
* - true: 启用监听(开发模式)
|
|
191
|
-
* - false: 禁用监听(生产模式)
|
|
192
|
-
*
|
|
193
|
-
* 使用示例: isDev: process.env.NODE_ENV === 'development'
|
|
194
|
-
*/
|
|
195
|
-
isDev?: boolean;
|
|
196
|
-
}
|
|
197
|
-
declare function createDevProxyCookie(options: UnifiedProxyCookieOptions): Plugin;
|
|
198
|
-
declare function getViteVersion(): string | null;
|
|
199
|
-
declare function getViteMajorVersion(): number;
|
|
200
|
-
|
|
354
|
+
/**
|
|
355
|
+
* Cookie 读取器配置选项
|
|
356
|
+
*/
|
|
201
357
|
interface CookieReaderOptions {
|
|
202
358
|
cookieFile: string;
|
|
203
359
|
encoding?: BufferEncoding;
|
|
204
360
|
}
|
|
361
|
+
/**
|
|
362
|
+
* Cookie 文件读取器类
|
|
363
|
+
*
|
|
364
|
+
* 提供从文件读取 Cookie 的功能,支持注释过滤和自动文件创建。
|
|
365
|
+
*/
|
|
205
366
|
declare class CookieReader {
|
|
367
|
+
/** 配置选项 */
|
|
206
368
|
protected options: CookieReaderOptions;
|
|
207
|
-
|
|
369
|
+
/** 是否启用调试模式 */
|
|
370
|
+
protected debug: boolean;
|
|
371
|
+
/**
|
|
372
|
+
* 构造函数
|
|
373
|
+
* @param options - 配置选项
|
|
374
|
+
* @param debug - 是否启用调试模式
|
|
375
|
+
*/
|
|
376
|
+
constructor(options: CookieReaderOptions, debug?: boolean);
|
|
377
|
+
/**
|
|
378
|
+
* 读取 Cookie 文件内容
|
|
379
|
+
*
|
|
380
|
+
* 支持过滤注释行(以 # 开头)和空行,将有效行用分号连接。
|
|
381
|
+
*
|
|
382
|
+
* @returns Cookie 字符串
|
|
383
|
+
*/
|
|
208
384
|
readCookie(): string;
|
|
385
|
+
/**
|
|
386
|
+
* 确保 Cookie 文件存在
|
|
387
|
+
*
|
|
388
|
+
* 如果文件不存在,会自动创建空文件。
|
|
389
|
+
* 如果父目录不存在,会自动创建目录。
|
|
390
|
+
*/
|
|
209
391
|
ensureCookieFile(): void;
|
|
210
392
|
}
|
|
393
|
+
/**
|
|
394
|
+
* 创建 Cookie 获取器函数
|
|
395
|
+
*
|
|
396
|
+
* 返回一个函数,每次调用时从文件读取最新的 Cookie 值。
|
|
397
|
+
*
|
|
398
|
+
* @param cookieFile - Cookie 文件路径
|
|
399
|
+
* @returns Cookie 获取函数
|
|
400
|
+
*/
|
|
211
401
|
declare function createCookieGetter(cookieFile: string): () => string;
|
|
212
402
|
|
|
403
|
+
/**
|
|
404
|
+
* Cookie 监听器配置选项
|
|
405
|
+
*/
|
|
213
406
|
interface CookieWatcherOptions {
|
|
214
407
|
cookieFile: string;
|
|
215
408
|
onCookieChange: (cookie: string) => void;
|
|
216
409
|
onError?: (error: Error) => void;
|
|
217
410
|
autoCreateFile?: boolean;
|
|
218
411
|
}
|
|
412
|
+
/**
|
|
413
|
+
* Cookie 文件监听器类
|
|
414
|
+
*
|
|
415
|
+
* 使用 chokidar 监听 Cookie 文件变化,当文件内容改变时触发回调。
|
|
416
|
+
* 支持自动创建文件和稳定性阈值配置。
|
|
417
|
+
*/
|
|
219
418
|
declare class CookieWatcher {
|
|
419
|
+
/** 文件监听器实例 */
|
|
220
420
|
private watcher;
|
|
421
|
+
/** 配置选项 */
|
|
221
422
|
private options;
|
|
423
|
+
/** Cookie 读取器 */
|
|
222
424
|
private cookieReader;
|
|
425
|
+
/** 上次读取的 Cookie 内容 */
|
|
223
426
|
private lastContent;
|
|
427
|
+
/**
|
|
428
|
+
* 构造函数
|
|
429
|
+
* @param options - 配置选项
|
|
430
|
+
*/
|
|
224
431
|
constructor(options: CookieWatcherOptions);
|
|
432
|
+
/**
|
|
433
|
+
* 文件变化处理函数
|
|
434
|
+
*
|
|
435
|
+
* 读取新的 Cookie 内容,如果与上次不同则触发回调。
|
|
436
|
+
*/
|
|
225
437
|
private handleChange;
|
|
438
|
+
/**
|
|
439
|
+
* 启动文件监听
|
|
440
|
+
*/
|
|
226
441
|
start(): void;
|
|
442
|
+
/**
|
|
443
|
+
* 停止文件监听
|
|
444
|
+
*/
|
|
227
445
|
stop(): void;
|
|
446
|
+
/**
|
|
447
|
+
* 获取当前 Cookie 值
|
|
448
|
+
* @returns 当前 Cookie 字符串
|
|
449
|
+
*/
|
|
228
450
|
getCurrentCookie(): string;
|
|
229
451
|
}
|
|
452
|
+
/**
|
|
453
|
+
* 创建并启动 Cookie 文件监听器
|
|
454
|
+
*
|
|
455
|
+
* @param cookieFile - Cookie 文件路径
|
|
456
|
+
* @param onCookieChange - Cookie 变化回调函数
|
|
457
|
+
* @param onError - 错误回调函数(可选)
|
|
458
|
+
* @returns CookieWatcher 实例
|
|
459
|
+
*/
|
|
230
460
|
declare function watchCookieFile(cookieFile: string, onCookieChange: (cookie: string) => void, onError?: (error: Error) => void): CookieWatcher;
|
|
231
461
|
|
|
232
462
|
/**
|
|
233
|
-
*
|
|
234
|
-
*
|
|
463
|
+
* 环境检测工具模块
|
|
464
|
+
*
|
|
465
|
+
* 提供智能环境检测功能,用于判断当前是否为生产构建环境,
|
|
466
|
+
* 从而决定是否启用文件监听等开发环境特性。
|
|
467
|
+
*
|
|
468
|
+
* @module env-detector
|
|
235
469
|
*/
|
|
236
470
|
/**
|
|
237
471
|
* 判断环境变量值是否表示生产环境
|
|
472
|
+
*
|
|
473
|
+
* @param value - 环境变量值
|
|
474
|
+
* @returns 是否为生产环境值
|
|
238
475
|
*/
|
|
239
476
|
declare function isProductionValue(value: string): boolean;
|
|
240
477
|
/**
|
|
@@ -261,4 +498,4 @@ declare function detectProductionEnvironment(customEnvs?: string[], debug?: bool
|
|
|
261
498
|
*/
|
|
262
499
|
declare function shouldEnableWatch(watch: boolean | 'auto', customEnvs?: string[], debug?: boolean, loggerPrefix?: string): boolean;
|
|
263
500
|
|
|
264
|
-
export { type AutoProxyConfigOptions, AutoProxyCookie, type AutoProxyCookieOptions, CookieReader, type CookieReaderOptions, CookieWatcher, type CookieWatcherOptions, type CreateFileCookieGetterOptions, type ErrorCallback, type ProxyConfig, type ProxyHooks, type
|
|
501
|
+
export { type AutoProxyConfigOptions, AutoProxyCookie, type AutoProxyCookieOptions, CookieReader, type CookieReaderOptions, CookieWatcher, type CookieWatcherOptions, type CreateFileCookieGetterOptions, type ErrorCallback, type ProxyConfig, type ProxyHooks, type ViteMiddlewareProxyOptions, type VueProxyConfigOptions, createAutoProxyConfig, createAutoProxyCookie, createCookieGetter, createFileCookieGetter, createVueProxyConfig, detectProductionEnvironment, isProductionValue, shouldEnableWatch, viteMiddlewareProxy, watchCookieFile };
|