@gylautorun/dev-proxy-cookie 1.0.0-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/LICENSE +21 -0
- package/README.md +743 -0
- package/dist/index.d.mts +264 -0
- package/dist/index.d.ts +264 -0
- package/dist/index.js +847 -0
- package/dist/index.min.js +4 -0
- package/dist/index.min.mjs +4 -0
- package/dist/index.mjs +801 -0
- package/package.json +83 -0
- package/src/index.ts +2 -0
- package/src/proxy/apply-dev-cookie-header.ts +14 -0
- package/src/proxy/core.ts +429 -0
- package/src/proxy/index.ts +5 -0
- package/src/proxy/vite-adapter.ts +98 -0
- package/src/proxy/vite-cookie-plugin.ts +94 -0
- package/src/proxy/vite-plugin.ts +66 -0
- package/src/proxy/vue-proxy-config.ts +192 -0
- package/src/utils/cookie-reader.ts +54 -0
- package/src/utils/cookie-watcher.ts +91 -0
- package/src/utils/env-detector.ts +155 -0
- package/src/utils/index.ts +3 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import * as net from 'net';
|
|
2
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
+
import { ViteDevServer, Plugin } from 'vite';
|
|
4
|
+
|
|
5
|
+
type ErrorCallback = (err: Error, req: IncomingMessage, res: ServerResponse | net.Socket) => void;
|
|
6
|
+
interface ProxyHooks {
|
|
7
|
+
onProxyReq?: (proxyReq: any, req: IncomingMessage, res: ServerResponse) => void;
|
|
8
|
+
onProxyRes?: (proxyRes: any, req: IncomingMessage, res: ServerResponse) => void;
|
|
9
|
+
onError?: ErrorCallback;
|
|
10
|
+
onWsError?: (err: Error, req: IncomingMessage, socket: net.Socket) => void;
|
|
11
|
+
}
|
|
12
|
+
interface AutoProxyCookieOptions {
|
|
13
|
+
cookieFile: string;
|
|
14
|
+
target: string;
|
|
15
|
+
debug?: boolean;
|
|
16
|
+
autoRestart?: boolean;
|
|
17
|
+
restartMarkerFile?: string;
|
|
18
|
+
proxyMap?: Record<string, string>;
|
|
19
|
+
ignorePaths?: string[];
|
|
20
|
+
ws?: boolean;
|
|
21
|
+
changeOrigin?: boolean;
|
|
22
|
+
secure?: boolean;
|
|
23
|
+
followRedirects?: boolean;
|
|
24
|
+
autoRewrite?: boolean;
|
|
25
|
+
protocolRewrite?: string;
|
|
26
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error';
|
|
27
|
+
cookieDomainRewrite?: false | string | {
|
|
28
|
+
[oldDomain: string]: string;
|
|
29
|
+
};
|
|
30
|
+
cookiePathRewrite?: false | string | {
|
|
31
|
+
[oldPath: string]: string;
|
|
32
|
+
};
|
|
33
|
+
headers?: {
|
|
34
|
+
[header: string]: string;
|
|
35
|
+
};
|
|
36
|
+
hooks?: ProxyHooks;
|
|
37
|
+
/**
|
|
38
|
+
* 是否为开发环境(优先级最高)
|
|
39
|
+
* 设置此参数后,将直接决定是否启用文件监听:
|
|
40
|
+
* - true: 启用监听(开发模式)
|
|
41
|
+
* - false: 禁用监听(生产模式)
|
|
42
|
+
*
|
|
43
|
+
* 使用示例: isDev: process.env.NODE_ENV === 'development'
|
|
44
|
+
*/
|
|
45
|
+
isDev?: boolean;
|
|
46
|
+
}
|
|
47
|
+
declare class AutoProxyCookie {
|
|
48
|
+
private options;
|
|
49
|
+
private currentCookie;
|
|
50
|
+
private server;
|
|
51
|
+
private proxyServer;
|
|
52
|
+
private watcher;
|
|
53
|
+
private cookieReader;
|
|
54
|
+
constructor(options: AutoProxyCookieOptions);
|
|
55
|
+
private handleCookieChange;
|
|
56
|
+
private getProxyUrl;
|
|
57
|
+
private isIgnoredPath;
|
|
58
|
+
private log;
|
|
59
|
+
private createProxyOptions;
|
|
60
|
+
private handleOnProxyReq;
|
|
61
|
+
private handleOnProxyRes;
|
|
62
|
+
private handleOnError;
|
|
63
|
+
private handleOnWsError;
|
|
64
|
+
setup(server: ViteDevServer): Promise<void>;
|
|
65
|
+
private startFileWatch;
|
|
66
|
+
stop(): void;
|
|
67
|
+
getCurrentCookie(): string;
|
|
68
|
+
}
|
|
69
|
+
declare function createAutoProxyCookie(options: AutoProxyCookieOptions): AutoProxyCookie;
|
|
70
|
+
|
|
71
|
+
interface ViteAutoProxyCookiePluginOptions extends AutoProxyCookieOptions {
|
|
72
|
+
name?: string;
|
|
73
|
+
/**
|
|
74
|
+
* 是否为开发环境(优先级最高)
|
|
75
|
+
* 设置此参数后,将直接决定是否启用文件监听:
|
|
76
|
+
* - true: 启用监听(开发模式)
|
|
77
|
+
* - false: 禁用监听(生产模式)
|
|
78
|
+
*
|
|
79
|
+
* 使用示例: isDev: process.env.NODE_ENV === 'development'
|
|
80
|
+
*/
|
|
81
|
+
isDev?: boolean;
|
|
82
|
+
}
|
|
83
|
+
declare function viteAutoProxyCookie(options: ViteAutoProxyCookiePluginOptions): Plugin;
|
|
84
|
+
|
|
85
|
+
interface ViteDevProxyCookieOptions {
|
|
86
|
+
cookieFile: string;
|
|
87
|
+
debug?: boolean;
|
|
88
|
+
onCookieChange?: (cookie: string) => void;
|
|
89
|
+
/**
|
|
90
|
+
* 是否监听文件变化
|
|
91
|
+
* - true: 始终监听
|
|
92
|
+
* - false: 从不监听
|
|
93
|
+
* - 'auto': 根据环境自动判断(默认)
|
|
94
|
+
* @default 'auto'
|
|
95
|
+
*/
|
|
96
|
+
watch?: boolean | 'auto';
|
|
97
|
+
/**
|
|
98
|
+
* 是否为开发环境(优先级最高)
|
|
99
|
+
* 设置此参数后,将直接决定是否启用文件监听:
|
|
100
|
+
* - true: 启用监听(开发模式)
|
|
101
|
+
* - false: 禁用监听(生产模式)
|
|
102
|
+
*
|
|
103
|
+
* 使用示例: isDev: process.env.NODE_ENV === 'development'
|
|
104
|
+
*/
|
|
105
|
+
isDev?: boolean;
|
|
106
|
+
}
|
|
107
|
+
declare function viteDevProxyCookie(options: ViteDevProxyCookieOptions): Plugin;
|
|
108
|
+
|
|
109
|
+
/** Options for {@link createFileCookieGetter}. */
|
|
110
|
+
interface CreateFileCookieGetterOptions {
|
|
111
|
+
/**
|
|
112
|
+
* 是否监听文件变化
|
|
113
|
+
* - true: 始终监听
|
|
114
|
+
* - false: 从不监听
|
|
115
|
+
* - 'auto': 根据环境自动判断(默认)
|
|
116
|
+
*
|
|
117
|
+
* Cookie 值每次代理请求时都会从磁盘读取,因此即使 watch 为 false,
|
|
118
|
+
* 修改 cookie 文件后也不需要重启开发服务器。
|
|
119
|
+
* @default 'auto'
|
|
120
|
+
*/
|
|
121
|
+
watch?: boolean | 'auto';
|
|
122
|
+
/** Log when the cookie file changes (only if `watch` is true). @default false */
|
|
123
|
+
debug?: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* 自定义生产环境变量名称列表,用于判断是否禁用监听
|
|
126
|
+
* 例如: ['MY_APP_ENV', 'BUILD_TYPE']
|
|
127
|
+
*/
|
|
128
|
+
productionEnvs?: string[];
|
|
129
|
+
/**
|
|
130
|
+
* 是否为开发环境(优先级最高)
|
|
131
|
+
* 设置此参数后,将直接决定是否启用文件监听:
|
|
132
|
+
* - true: 启用监听(开发模式)
|
|
133
|
+
* - false: 禁用监听(生产模式)
|
|
134
|
+
*
|
|
135
|
+
* 使用示例: isDev: process.env.NODE_ENV === 'development'
|
|
136
|
+
*/
|
|
137
|
+
isDev?: boolean;
|
|
138
|
+
}
|
|
139
|
+
interface VueProxyConfigOptions {
|
|
140
|
+
getCookie?: () => string;
|
|
141
|
+
debug?: boolean;
|
|
142
|
+
headers?: Record<string, string>;
|
|
143
|
+
ws?: boolean;
|
|
144
|
+
changeOrigin?: boolean;
|
|
145
|
+
secure?: boolean;
|
|
146
|
+
onError?: (err: Error) => void;
|
|
147
|
+
}
|
|
148
|
+
interface ProxyConfig {
|
|
149
|
+
ws: boolean;
|
|
150
|
+
target: string;
|
|
151
|
+
changeOrigin: boolean;
|
|
152
|
+
secure: boolean;
|
|
153
|
+
onProxyReq: (proxyReq: any, req: IncomingMessage) => void;
|
|
154
|
+
onProxyRes?: (proxyRes: any, req: IncomingMessage) => void;
|
|
155
|
+
onError: (err: Error) => void;
|
|
156
|
+
headers?: Record<string, string>;
|
|
157
|
+
}
|
|
158
|
+
declare function createVueProxyConfig(target: string, options?: VueProxyConfigOptions): ProxyConfig;
|
|
159
|
+
declare function createFileCookieGetter(cookieFile: string, options?: CreateFileCookieGetterOptions): () => string;
|
|
160
|
+
interface AutoProxyConfigOptions extends VueProxyConfigOptions {
|
|
161
|
+
target: string;
|
|
162
|
+
ignorePaths?: string[];
|
|
163
|
+
includePaths?: string[];
|
|
164
|
+
additionalProxies?: Record<string, string>;
|
|
165
|
+
}
|
|
166
|
+
declare function createAutoProxyConfig(options: AutoProxyConfigOptions): Record<string, ProxyConfig>;
|
|
167
|
+
|
|
168
|
+
interface UnifiedProxyCookieOptions {
|
|
169
|
+
cookieFile: string;
|
|
170
|
+
target?: string;
|
|
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
|
+
|
|
201
|
+
interface CookieReaderOptions {
|
|
202
|
+
cookieFile: string;
|
|
203
|
+
encoding?: BufferEncoding;
|
|
204
|
+
}
|
|
205
|
+
declare class CookieReader {
|
|
206
|
+
protected options: CookieReaderOptions;
|
|
207
|
+
constructor(options: CookieReaderOptions);
|
|
208
|
+
readCookie(): string;
|
|
209
|
+
ensureCookieFile(): void;
|
|
210
|
+
}
|
|
211
|
+
declare function createCookieGetter(cookieFile: string): () => string;
|
|
212
|
+
|
|
213
|
+
interface CookieWatcherOptions {
|
|
214
|
+
cookieFile: string;
|
|
215
|
+
onCookieChange: (cookie: string) => void;
|
|
216
|
+
onError?: (error: Error) => void;
|
|
217
|
+
autoCreateFile?: boolean;
|
|
218
|
+
}
|
|
219
|
+
declare class CookieWatcher {
|
|
220
|
+
private watcher;
|
|
221
|
+
private options;
|
|
222
|
+
private cookieReader;
|
|
223
|
+
private lastContent;
|
|
224
|
+
constructor(options: CookieWatcherOptions);
|
|
225
|
+
private handleChange;
|
|
226
|
+
start(): void;
|
|
227
|
+
stop(): void;
|
|
228
|
+
getCurrentCookie(): string;
|
|
229
|
+
}
|
|
230
|
+
declare function watchCookieFile(cookieFile: string, onCookieChange: (cookie: string) => void, onError?: (error: Error) => void): CookieWatcher;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* 环境检测工具函数
|
|
234
|
+
* 用于智能判断当前是否为生产构建环境
|
|
235
|
+
*/
|
|
236
|
+
/**
|
|
237
|
+
* 判断环境变量值是否表示生产环境
|
|
238
|
+
*/
|
|
239
|
+
declare function isProductionValue(value: string): boolean;
|
|
240
|
+
/**
|
|
241
|
+
* 智能检测当前是否为生产构建环境
|
|
242
|
+
* 通过多种方式综合判断,避免依赖单一环境变量
|
|
243
|
+
*
|
|
244
|
+
* @param customEnvs 用户自定义的环境变量名称列表
|
|
245
|
+
* @param debug 是否输出调试日志
|
|
246
|
+
* @param loggerPrefix 日志前缀,用于区分不同模块
|
|
247
|
+
* @returns 是否为生产环境
|
|
248
|
+
*/
|
|
249
|
+
declare function detectProductionEnvironment(customEnvs?: string[], debug?: boolean, loggerPrefix?: string): boolean;
|
|
250
|
+
/**
|
|
251
|
+
* 判断是否应该启用文件监听
|
|
252
|
+
*
|
|
253
|
+
* 注意:此函数仅在 isDev 参数未设置时调用,用于智能判断环境
|
|
254
|
+
* 如果用户已通过 isDev 参数明确指定环境,则不会调用此函数
|
|
255
|
+
*
|
|
256
|
+
* @param watch 用户设置的 watch 选项
|
|
257
|
+
* @param customEnvs 用户自定义的环境变量列表
|
|
258
|
+
* @param debug 是否输出调试日志
|
|
259
|
+
* @param loggerPrefix 日志前缀
|
|
260
|
+
* @returns 是否应该启用监听
|
|
261
|
+
*/
|
|
262
|
+
declare function shouldEnableWatch(watch: boolean | 'auto', customEnvs?: string[], debug?: boolean, loggerPrefix?: string): boolean;
|
|
263
|
+
|
|
264
|
+
export { type AutoProxyConfigOptions, AutoProxyCookie, type AutoProxyCookieOptions, CookieReader, type CookieReaderOptions, CookieWatcher, type CookieWatcherOptions, type CreateFileCookieGetterOptions, type ErrorCallback, type ProxyConfig, type ProxyHooks, type UnifiedProxyCookieOptions, type ViteAutoProxyCookiePluginOptions, type ViteDevProxyCookieOptions, type VueProxyConfigOptions, createAutoProxyConfig, createAutoProxyCookie, createCookieGetter, createDevProxyCookie, createFileCookieGetter, createVueProxyConfig, detectProductionEnvironment, getViteMajorVersion, getViteVersion, isProductionValue, shouldEnableWatch, viteAutoProxyCookie, viteDevProxyCookie, watchCookieFile };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import * as net from 'net';
|
|
2
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
+
import { ViteDevServer, Plugin } from 'vite';
|
|
4
|
+
|
|
5
|
+
type ErrorCallback = (err: Error, req: IncomingMessage, res: ServerResponse | net.Socket) => void;
|
|
6
|
+
interface ProxyHooks {
|
|
7
|
+
onProxyReq?: (proxyReq: any, req: IncomingMessage, res: ServerResponse) => void;
|
|
8
|
+
onProxyRes?: (proxyRes: any, req: IncomingMessage, res: ServerResponse) => void;
|
|
9
|
+
onError?: ErrorCallback;
|
|
10
|
+
onWsError?: (err: Error, req: IncomingMessage, socket: net.Socket) => void;
|
|
11
|
+
}
|
|
12
|
+
interface AutoProxyCookieOptions {
|
|
13
|
+
cookieFile: string;
|
|
14
|
+
target: string;
|
|
15
|
+
debug?: boolean;
|
|
16
|
+
autoRestart?: boolean;
|
|
17
|
+
restartMarkerFile?: string;
|
|
18
|
+
proxyMap?: Record<string, string>;
|
|
19
|
+
ignorePaths?: string[];
|
|
20
|
+
ws?: boolean;
|
|
21
|
+
changeOrigin?: boolean;
|
|
22
|
+
secure?: boolean;
|
|
23
|
+
followRedirects?: boolean;
|
|
24
|
+
autoRewrite?: boolean;
|
|
25
|
+
protocolRewrite?: string;
|
|
26
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error';
|
|
27
|
+
cookieDomainRewrite?: false | string | {
|
|
28
|
+
[oldDomain: string]: string;
|
|
29
|
+
};
|
|
30
|
+
cookiePathRewrite?: false | string | {
|
|
31
|
+
[oldPath: string]: string;
|
|
32
|
+
};
|
|
33
|
+
headers?: {
|
|
34
|
+
[header: string]: string;
|
|
35
|
+
};
|
|
36
|
+
hooks?: ProxyHooks;
|
|
37
|
+
/**
|
|
38
|
+
* 是否为开发环境(优先级最高)
|
|
39
|
+
* 设置此参数后,将直接决定是否启用文件监听:
|
|
40
|
+
* - true: 启用监听(开发模式)
|
|
41
|
+
* - false: 禁用监听(生产模式)
|
|
42
|
+
*
|
|
43
|
+
* 使用示例: isDev: process.env.NODE_ENV === 'development'
|
|
44
|
+
*/
|
|
45
|
+
isDev?: boolean;
|
|
46
|
+
}
|
|
47
|
+
declare class AutoProxyCookie {
|
|
48
|
+
private options;
|
|
49
|
+
private currentCookie;
|
|
50
|
+
private server;
|
|
51
|
+
private proxyServer;
|
|
52
|
+
private watcher;
|
|
53
|
+
private cookieReader;
|
|
54
|
+
constructor(options: AutoProxyCookieOptions);
|
|
55
|
+
private handleCookieChange;
|
|
56
|
+
private getProxyUrl;
|
|
57
|
+
private isIgnoredPath;
|
|
58
|
+
private log;
|
|
59
|
+
private createProxyOptions;
|
|
60
|
+
private handleOnProxyReq;
|
|
61
|
+
private handleOnProxyRes;
|
|
62
|
+
private handleOnError;
|
|
63
|
+
private handleOnWsError;
|
|
64
|
+
setup(server: ViteDevServer): Promise<void>;
|
|
65
|
+
private startFileWatch;
|
|
66
|
+
stop(): void;
|
|
67
|
+
getCurrentCookie(): string;
|
|
68
|
+
}
|
|
69
|
+
declare function createAutoProxyCookie(options: AutoProxyCookieOptions): AutoProxyCookie;
|
|
70
|
+
|
|
71
|
+
interface ViteAutoProxyCookiePluginOptions extends AutoProxyCookieOptions {
|
|
72
|
+
name?: string;
|
|
73
|
+
/**
|
|
74
|
+
* 是否为开发环境(优先级最高)
|
|
75
|
+
* 设置此参数后,将直接决定是否启用文件监听:
|
|
76
|
+
* - true: 启用监听(开发模式)
|
|
77
|
+
* - false: 禁用监听(生产模式)
|
|
78
|
+
*
|
|
79
|
+
* 使用示例: isDev: process.env.NODE_ENV === 'development'
|
|
80
|
+
*/
|
|
81
|
+
isDev?: boolean;
|
|
82
|
+
}
|
|
83
|
+
declare function viteAutoProxyCookie(options: ViteAutoProxyCookiePluginOptions): Plugin;
|
|
84
|
+
|
|
85
|
+
interface ViteDevProxyCookieOptions {
|
|
86
|
+
cookieFile: string;
|
|
87
|
+
debug?: boolean;
|
|
88
|
+
onCookieChange?: (cookie: string) => void;
|
|
89
|
+
/**
|
|
90
|
+
* 是否监听文件变化
|
|
91
|
+
* - true: 始终监听
|
|
92
|
+
* - false: 从不监听
|
|
93
|
+
* - 'auto': 根据环境自动判断(默认)
|
|
94
|
+
* @default 'auto'
|
|
95
|
+
*/
|
|
96
|
+
watch?: boolean | 'auto';
|
|
97
|
+
/**
|
|
98
|
+
* 是否为开发环境(优先级最高)
|
|
99
|
+
* 设置此参数后,将直接决定是否启用文件监听:
|
|
100
|
+
* - true: 启用监听(开发模式)
|
|
101
|
+
* - false: 禁用监听(生产模式)
|
|
102
|
+
*
|
|
103
|
+
* 使用示例: isDev: process.env.NODE_ENV === 'development'
|
|
104
|
+
*/
|
|
105
|
+
isDev?: boolean;
|
|
106
|
+
}
|
|
107
|
+
declare function viteDevProxyCookie(options: ViteDevProxyCookieOptions): Plugin;
|
|
108
|
+
|
|
109
|
+
/** Options for {@link createFileCookieGetter}. */
|
|
110
|
+
interface CreateFileCookieGetterOptions {
|
|
111
|
+
/**
|
|
112
|
+
* 是否监听文件变化
|
|
113
|
+
* - true: 始终监听
|
|
114
|
+
* - false: 从不监听
|
|
115
|
+
* - 'auto': 根据环境自动判断(默认)
|
|
116
|
+
*
|
|
117
|
+
* Cookie 值每次代理请求时都会从磁盘读取,因此即使 watch 为 false,
|
|
118
|
+
* 修改 cookie 文件后也不需要重启开发服务器。
|
|
119
|
+
* @default 'auto'
|
|
120
|
+
*/
|
|
121
|
+
watch?: boolean | 'auto';
|
|
122
|
+
/** Log when the cookie file changes (only if `watch` is true). @default false */
|
|
123
|
+
debug?: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* 自定义生产环境变量名称列表,用于判断是否禁用监听
|
|
126
|
+
* 例如: ['MY_APP_ENV', 'BUILD_TYPE']
|
|
127
|
+
*/
|
|
128
|
+
productionEnvs?: string[];
|
|
129
|
+
/**
|
|
130
|
+
* 是否为开发环境(优先级最高)
|
|
131
|
+
* 设置此参数后,将直接决定是否启用文件监听:
|
|
132
|
+
* - true: 启用监听(开发模式)
|
|
133
|
+
* - false: 禁用监听(生产模式)
|
|
134
|
+
*
|
|
135
|
+
* 使用示例: isDev: process.env.NODE_ENV === 'development'
|
|
136
|
+
*/
|
|
137
|
+
isDev?: boolean;
|
|
138
|
+
}
|
|
139
|
+
interface VueProxyConfigOptions {
|
|
140
|
+
getCookie?: () => string;
|
|
141
|
+
debug?: boolean;
|
|
142
|
+
headers?: Record<string, string>;
|
|
143
|
+
ws?: boolean;
|
|
144
|
+
changeOrigin?: boolean;
|
|
145
|
+
secure?: boolean;
|
|
146
|
+
onError?: (err: Error) => void;
|
|
147
|
+
}
|
|
148
|
+
interface ProxyConfig {
|
|
149
|
+
ws: boolean;
|
|
150
|
+
target: string;
|
|
151
|
+
changeOrigin: boolean;
|
|
152
|
+
secure: boolean;
|
|
153
|
+
onProxyReq: (proxyReq: any, req: IncomingMessage) => void;
|
|
154
|
+
onProxyRes?: (proxyRes: any, req: IncomingMessage) => void;
|
|
155
|
+
onError: (err: Error) => void;
|
|
156
|
+
headers?: Record<string, string>;
|
|
157
|
+
}
|
|
158
|
+
declare function createVueProxyConfig(target: string, options?: VueProxyConfigOptions): ProxyConfig;
|
|
159
|
+
declare function createFileCookieGetter(cookieFile: string, options?: CreateFileCookieGetterOptions): () => string;
|
|
160
|
+
interface AutoProxyConfigOptions extends VueProxyConfigOptions {
|
|
161
|
+
target: string;
|
|
162
|
+
ignorePaths?: string[];
|
|
163
|
+
includePaths?: string[];
|
|
164
|
+
additionalProxies?: Record<string, string>;
|
|
165
|
+
}
|
|
166
|
+
declare function createAutoProxyConfig(options: AutoProxyConfigOptions): Record<string, ProxyConfig>;
|
|
167
|
+
|
|
168
|
+
interface UnifiedProxyCookieOptions {
|
|
169
|
+
cookieFile: string;
|
|
170
|
+
target?: string;
|
|
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
|
+
|
|
201
|
+
interface CookieReaderOptions {
|
|
202
|
+
cookieFile: string;
|
|
203
|
+
encoding?: BufferEncoding;
|
|
204
|
+
}
|
|
205
|
+
declare class CookieReader {
|
|
206
|
+
protected options: CookieReaderOptions;
|
|
207
|
+
constructor(options: CookieReaderOptions);
|
|
208
|
+
readCookie(): string;
|
|
209
|
+
ensureCookieFile(): void;
|
|
210
|
+
}
|
|
211
|
+
declare function createCookieGetter(cookieFile: string): () => string;
|
|
212
|
+
|
|
213
|
+
interface CookieWatcherOptions {
|
|
214
|
+
cookieFile: string;
|
|
215
|
+
onCookieChange: (cookie: string) => void;
|
|
216
|
+
onError?: (error: Error) => void;
|
|
217
|
+
autoCreateFile?: boolean;
|
|
218
|
+
}
|
|
219
|
+
declare class CookieWatcher {
|
|
220
|
+
private watcher;
|
|
221
|
+
private options;
|
|
222
|
+
private cookieReader;
|
|
223
|
+
private lastContent;
|
|
224
|
+
constructor(options: CookieWatcherOptions);
|
|
225
|
+
private handleChange;
|
|
226
|
+
start(): void;
|
|
227
|
+
stop(): void;
|
|
228
|
+
getCurrentCookie(): string;
|
|
229
|
+
}
|
|
230
|
+
declare function watchCookieFile(cookieFile: string, onCookieChange: (cookie: string) => void, onError?: (error: Error) => void): CookieWatcher;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* 环境检测工具函数
|
|
234
|
+
* 用于智能判断当前是否为生产构建环境
|
|
235
|
+
*/
|
|
236
|
+
/**
|
|
237
|
+
* 判断环境变量值是否表示生产环境
|
|
238
|
+
*/
|
|
239
|
+
declare function isProductionValue(value: string): boolean;
|
|
240
|
+
/**
|
|
241
|
+
* 智能检测当前是否为生产构建环境
|
|
242
|
+
* 通过多种方式综合判断,避免依赖单一环境变量
|
|
243
|
+
*
|
|
244
|
+
* @param customEnvs 用户自定义的环境变量名称列表
|
|
245
|
+
* @param debug 是否输出调试日志
|
|
246
|
+
* @param loggerPrefix 日志前缀,用于区分不同模块
|
|
247
|
+
* @returns 是否为生产环境
|
|
248
|
+
*/
|
|
249
|
+
declare function detectProductionEnvironment(customEnvs?: string[], debug?: boolean, loggerPrefix?: string): boolean;
|
|
250
|
+
/**
|
|
251
|
+
* 判断是否应该启用文件监听
|
|
252
|
+
*
|
|
253
|
+
* 注意:此函数仅在 isDev 参数未设置时调用,用于智能判断环境
|
|
254
|
+
* 如果用户已通过 isDev 参数明确指定环境,则不会调用此函数
|
|
255
|
+
*
|
|
256
|
+
* @param watch 用户设置的 watch 选项
|
|
257
|
+
* @param customEnvs 用户自定义的环境变量列表
|
|
258
|
+
* @param debug 是否输出调试日志
|
|
259
|
+
* @param loggerPrefix 日志前缀
|
|
260
|
+
* @returns 是否应该启用监听
|
|
261
|
+
*/
|
|
262
|
+
declare function shouldEnableWatch(watch: boolean | 'auto', customEnvs?: string[], debug?: boolean, loggerPrefix?: string): boolean;
|
|
263
|
+
|
|
264
|
+
export { type AutoProxyConfigOptions, AutoProxyCookie, type AutoProxyCookieOptions, CookieReader, type CookieReaderOptions, CookieWatcher, type CookieWatcherOptions, type CreateFileCookieGetterOptions, type ErrorCallback, type ProxyConfig, type ProxyHooks, type UnifiedProxyCookieOptions, type ViteAutoProxyCookiePluginOptions, type ViteDevProxyCookieOptions, type VueProxyConfigOptions, createAutoProxyConfig, createAutoProxyCookie, createCookieGetter, createDevProxyCookie, createFileCookieGetter, createVueProxyConfig, detectProductionEnvironment, getViteMajorVersion, getViteVersion, isProductionValue, shouldEnableWatch, viteAutoProxyCookie, viteDevProxyCookie, watchCookieFile };
|