@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.
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Vue CLI 代理配置模块
3
+ *
4
+ * 提供 Vue CLI 开发服务器的代理配置功能,支持从文件读取 Cookie 并注入代理请求。
5
+ * 核心函数包括 createFileCookieGetter 和 createVueProxyConfig。
6
+ *
7
+ * @module vue-proxy-config
8
+ */
1
9
  import type { IncomingMessage } from 'http';
2
10
  import * as path from 'path';
3
11
  import { CookieReader, watchCookieFile, shouldEnableWatch } from '../utils';
@@ -34,27 +42,65 @@ export interface CreateFileCookieGetterOptions {
34
42
  isDev?: boolean;
35
43
  }
36
44
 
45
+ /**
46
+ * Vue 代理配置选项
47
+ */
37
48
  export interface VueProxyConfigOptions {
49
+ /** Cookie 获取函数 */
38
50
  getCookie?: () => string;
51
+ /** 是否输出调试日志 */
39
52
  debug?: boolean;
53
+ /**
54
+ * 是否使用 Cookie 文件中的 Cookie 注入到请求中
55
+ * - true: 使用文件中的 Cookie(默认)
56
+ * - false: 不注入 Cookie,使用浏览器发送的 Cookie
57
+ *
58
+ * 当使用账号密码登录时,设置为 false,避免覆盖浏览器的登录 Cookie
59
+ */
60
+ useCookie?: boolean;
61
+ /** 自定义请求头 */
40
62
  headers?: Record<string, string>;
63
+ /** 是否启用 WebSocket 代理 */
41
64
  ws?: boolean;
65
+ /** 是否修改请求头中的 Origin */
42
66
  changeOrigin?: boolean;
67
+ /** 是否验证 SSL 证书 */
43
68
  secure?: boolean;
69
+ /** 错误回调函数 */
44
70
  onError?: (err: Error) => void;
45
71
  }
46
72
 
73
+ /**
74
+ * Vue CLI 代理配置接口
75
+ *
76
+ * 符合 Vue CLI 代理配置格式的对象结构
77
+ */
47
78
  export interface ProxyConfig {
79
+ /** 是否启用 WebSocket 代理 */
48
80
  ws: boolean;
81
+ /** 代理目标地址 */
49
82
  target: string;
83
+ /** 是否修改请求头中的 Origin */
50
84
  changeOrigin: boolean;
85
+ /** 是否验证 SSL 证书 */
51
86
  secure: boolean;
87
+ /** 代理请求前的回调函数 */
52
88
  onProxyReq: (proxyReq: any, req: IncomingMessage) => void;
89
+ /** 代理响应后的回调函数(可选) */
53
90
  onProxyRes?: (proxyRes: any, req: IncomingMessage) => void;
91
+ /** 错误处理回调函数 */
54
92
  onError: (err: Error) => void;
93
+ /** 自定义请求头 */
55
94
  headers?: Record<string, string>;
56
95
  }
57
96
 
97
+ /**
98
+ * 创建 Vue CLI 代理配置
99
+ *
100
+ * @param target - 代理目标地址
101
+ * @param options - 配置选项
102
+ * @returns Vue CLI 代理配置对象
103
+ */
58
104
  export function createVueProxyConfig(
59
105
  target: string,
60
106
  options: VueProxyConfigOptions = {}
@@ -62,6 +108,7 @@ export function createVueProxyConfig(
62
108
  const {
63
109
  getCookie,
64
110
  debug = false,
111
+ useCookie = true,
65
112
  headers = {},
66
113
  ws = false,
67
114
  changeOrigin = true,
@@ -76,13 +123,18 @@ export function createVueProxyConfig(
76
123
  secure,
77
124
  headers,
78
125
  onProxyReq: (proxyReq: any, req: IncomingMessage) => {
79
- const cookie = getCookie ? getCookie() : '';
80
- if (cookie) {
81
- applyDevCookieHeader(proxyReq, cookie);
82
- }
83
- if (debug) {
84
- const reqPath = req.url || '/';
85
- console.log('[Proxy Request]', reqPath, req.method, cookie ? '(with cookie)' : '(no cookie)');
126
+ const reqPath = req.url || '/';
127
+
128
+ if (useCookie) {
129
+ const cookie = getCookie ? getCookie() : '';
130
+ if (cookie) {
131
+ applyDevCookieHeader(proxyReq, cookie);
132
+ }
133
+ if (debug) {
134
+ console.log('[Proxy Request]', reqPath, req.method, cookie ? '(with cookie)' : '(no cookie)');
135
+ }
136
+ } else if (debug) {
137
+ console.log('[Proxy Request]', reqPath, req.method, '(useCookie is false, skipping cookie injection)');
86
138
  }
87
139
  },
88
140
  onError: customOnError || ((err: Error) => {
@@ -93,17 +145,26 @@ export function createVueProxyConfig(
93
145
  return config;
94
146
  }
95
147
 
148
+ /**
149
+ * 创建文件 Cookie 获取器
150
+ *
151
+ * 从指定文件读取 Cookie 值,支持文件监听功能。
152
+ *
153
+ * @param cookieFile - Cookie 文件路径
154
+ * @param options - 配置选项
155
+ * @returns Cookie 获取函数
156
+ */
96
157
  export function createFileCookieGetter(
97
158
  cookieFile: string,
98
159
  options: CreateFileCookieGetterOptions = {}
99
160
  ): () => string {
100
161
  const {
101
162
  watch = 'auto',
102
- debug = false,
163
+ debug = true,
103
164
  productionEnvs = [],
104
165
  isDev
105
166
  } = options;
106
- const reader = new CookieReader({ cookieFile: path.resolve(cookieFile) });
167
+ const reader = new CookieReader({ cookieFile: path.resolve(cookieFile) }, debug);
107
168
 
108
169
  // 判断是否应该启用监听
109
170
  // isDev 参数优先级最高,直接决定是否启用监听
@@ -139,21 +200,36 @@ export function createFileCookieGetter(
139
200
  return () => reader.readCookie();
140
201
  }
141
202
 
203
+ /**
204
+ * 自动代理配置选项
205
+ */
142
206
  export interface AutoProxyConfigOptions extends VueProxyConfigOptions {
207
+ /** 代理目标地址 */
143
208
  target: string;
209
+ /** 忽略的路径列表(不代理这些路径) */
144
210
  ignorePaths?: string[];
211
+ /** 包含的路径列表(只代理这些路径) */
145
212
  includePaths?: string[];
213
+ /** 额外的代理配置 */
146
214
  additionalProxies?: Record<string, string>;
147
215
  }
148
216
 
217
+ /**
218
+ * 创建自动代理配置
219
+ *
220
+ * 根据配置自动生成 Vue CLI 代理配置对象,支持忽略路径和包含路径两种模式。
221
+ *
222
+ * @param options - 配置选项
223
+ * @returns Vue CLI 代理配置对象映射
224
+ */
149
225
  export function createAutoProxyConfig(options: AutoProxyConfigOptions): Record<string, ProxyConfig> {
150
- const { target, ignorePaths = [], includePaths = [], additionalProxies = {}, getCookie, debug, headers } = options;
226
+ const { target, ignorePaths = [], includePaths = [], additionalProxies = {}, getCookie, debug, headers, useCookie = true } = options;
151
227
 
152
228
  const result: Record<string, ProxyConfig> = {};
153
229
 
154
230
  if (includePaths.length > 0) {
155
231
  for (const proxyPath of includePaths) {
156
- result[proxyPath] = createVueProxyConfig(target, { getCookie, debug, headers });
232
+ result[proxyPath] = createVueProxyConfig(target, { getCookie, debug, headers, useCookie });
157
233
  }
158
234
  } else {
159
235
  const defaultProxy: ProxyConfig = {
@@ -169,12 +245,16 @@ export function createAutoProxyConfig(options: AutoProxyConfigOptions): Record<s
169
245
  return;
170
246
  }
171
247
 
172
- const cookie = getCookie ? getCookie() : '';
173
- if (cookie) {
174
- applyDevCookieHeader(proxyReq, cookie);
175
- }
176
- if (debug) {
177
- console.log('[Proxy Request]', reqPath, req.method, cookie ? '(with cookie)' : '(no cookie)');
248
+ if (useCookie) {
249
+ const cookie = getCookie ? getCookie() : '';
250
+ if (cookie) {
251
+ applyDevCookieHeader(proxyReq, cookie);
252
+ }
253
+ if (debug) {
254
+ console.log('[Proxy Request]', reqPath, req.method, cookie ? '(with cookie)' : '(no cookie)');
255
+ }
256
+ } else if (debug) {
257
+ console.log('[Proxy Request]', reqPath, req.method, '(useCookie is false, skipping cookie injection)');
178
258
  }
179
259
  },
180
260
  onError: (err: Error) => {
@@ -185,7 +265,7 @@ export function createAutoProxyConfig(options: AutoProxyConfigOptions): Record<s
185
265
  }
186
266
 
187
267
  for (const [proxyPath, proxyTarget] of Object.entries(additionalProxies)) {
188
- result[proxyPath] = createVueProxyConfig(proxyTarget, { getCookie, debug, headers });
268
+ result[proxyPath] = createVueProxyConfig(proxyTarget, { getCookie, debug, headers, useCookie });
189
269
  }
190
270
 
191
271
  return result;
@@ -1,39 +1,102 @@
1
+ /**
2
+ * Cookie 文件读取器模块
3
+ *
4
+ * 提供从文件读取 Cookie 的功能,支持注释过滤和自动文件创建。
5
+ *
6
+ * @module cookie-reader
7
+ */
1
8
  import * as fs from 'fs';
2
9
  import * as path from 'path';
3
10
 
11
+ /**
12
+ * Cookie 读取器配置选项
13
+ */
4
14
  export interface CookieReaderOptions {
5
15
  cookieFile: string;
6
16
  encoding?: BufferEncoding;
7
17
  }
8
18
 
19
+ /**
20
+ * Cookie 文件读取器类
21
+ *
22
+ * 提供从文件读取 Cookie 的功能,支持注释过滤和自动文件创建。
23
+ */
9
24
  export class CookieReader {
25
+ /** 配置选项 */
10
26
  protected options: CookieReaderOptions;
27
+ /** 是否启用调试模式 */
28
+ protected debug: boolean;
11
29
 
12
- constructor(options: CookieReaderOptions) {
30
+ /**
31
+ * 构造函数
32
+ * @param options - 配置选项
33
+ * @param debug - 是否启用调试模式
34
+ */
35
+ constructor(options: CookieReaderOptions, debug: boolean = false) {
13
36
  this.options = {
14
37
  encoding: 'utf-8',
15
38
  ...options,
16
39
  };
40
+ this.debug = debug;
17
41
  }
18
42
 
43
+ /**
44
+ * 读取 Cookie 文件内容
45
+ *
46
+ * 支持过滤注释行(以 # 开头)和空行,将有效行用分号连接。
47
+ *
48
+ * @returns Cookie 字符串
49
+ */
19
50
  readCookie(): string {
20
51
  try {
21
52
  const filePath = path.resolve(this.options.cookieFile);
53
+
54
+ if (this.debug) {
55
+ console.log('[CookieReader] Resolved cookie file path:', filePath);
56
+ console.log('[CookieReader] File exists:', fs.existsSync(filePath));
57
+ }
58
+
22
59
  if (fs.existsSync(filePath)) {
23
60
  const content = fs.readFileSync(filePath, this.options.encoding || 'utf-8');
61
+
62
+ if (this.debug) {
63
+ console.log('[CookieReader] File content length:', content.length);
64
+ }
65
+
24
66
  // 过滤注释行(以 # 开头)和空行,然后合并成一行
25
67
  const lines = content.split('\n');
26
68
  const cookieLines = lines
27
69
  .map(line => line.trim())
28
70
  .filter(line => line && !line.startsWith('#'));
29
- return cookieLines.join('; ');
71
+
72
+ const result = cookieLines.join('; ');
73
+
74
+ if (this.debug) {
75
+ console.log('[CookieReader] Parsed cookie:', result ? '(has cookie)' : '(empty)');
76
+ }
77
+
78
+ return result;
79
+ }
80
+
81
+ if (this.debug) {
82
+ console.log('[CookieReader] Cookie file not found:', filePath);
30
83
  }
84
+
31
85
  return '';
32
- } catch {
86
+ } catch (err) {
87
+ if (this.debug) {
88
+ console.error('[CookieReader] Error reading cookie file:', (err as Error).message);
89
+ }
33
90
  return '';
34
91
  }
35
92
  }
36
93
 
94
+ /**
95
+ * 确保 Cookie 文件存在
96
+ *
97
+ * 如果文件不存在,会自动创建空文件。
98
+ * 如果父目录不存在,会自动创建目录。
99
+ */
37
100
  ensureCookieFile(): void {
38
101
  const filePath = path.resolve(this.options.cookieFile);
39
102
  const dir = path.dirname(filePath);
@@ -48,6 +111,14 @@ export class CookieReader {
48
111
  }
49
112
  }
50
113
 
114
+ /**
115
+ * 创建 Cookie 获取器函数
116
+ *
117
+ * 返回一个函数,每次调用时从文件读取最新的 Cookie 值。
118
+ *
119
+ * @param cookieFile - Cookie 文件路径
120
+ * @returns Cookie 获取函数
121
+ */
51
122
  export function createCookieGetter(cookieFile: string): () => string {
52
123
  const reader = new CookieReader({ cookieFile });
53
124
  return () => reader.readCookie();
@@ -1,8 +1,19 @@
1
+ /**
2
+ * Cookie 文件监听器模块
3
+ *
4
+ * 使用 chokidar 监听 Cookie 文件变化,当文件内容改变时触发回调。
5
+ * 支持自动创建文件和稳定性阈值配置。
6
+ *
7
+ * @module cookie-watcher
8
+ */
1
9
  import * as fs from 'fs';
2
10
  import * as path from 'path';
3
11
  import chokidar, { FSWatcher } from 'chokidar';
4
12
  import { CookieReader } from './cookie-reader';
5
13
 
14
+ /**
15
+ * Cookie 监听器配置选项
16
+ */
6
17
  export interface CookieWatcherOptions {
7
18
  cookieFile: string;
8
19
  onCookieChange: (cookie: string) => void;
@@ -10,12 +21,26 @@ export interface CookieWatcherOptions {
10
21
  autoCreateFile?: boolean;
11
22
  }
12
23
 
24
+ /**
25
+ * Cookie 文件监听器类
26
+ *
27
+ * 使用 chokidar 监听 Cookie 文件变化,当文件内容改变时触发回调。
28
+ * 支持自动创建文件和稳定性阈值配置。
29
+ */
13
30
  export class CookieWatcher {
31
+ /** 文件监听器实例 */
14
32
  private watcher: FSWatcher | null = null;
33
+ /** 配置选项 */
15
34
  private options: CookieWatcherOptions;
35
+ /** Cookie 读取器 */
16
36
  private cookieReader: CookieReader;
37
+ /** 上次读取的 Cookie 内容 */
17
38
  private lastContent: string = '';
18
39
 
40
+ /**
41
+ * 构造函数
42
+ * @param options - 配置选项
43
+ */
19
44
  constructor(options: CookieWatcherOptions) {
20
45
  this.options = {
21
46
  autoCreateFile: true,
@@ -24,6 +49,11 @@ export class CookieWatcher {
24
49
  this.cookieReader = new CookieReader({ cookieFile: options.cookieFile });
25
50
  }
26
51
 
52
+ /**
53
+ * 文件变化处理函数
54
+ *
55
+ * 读取新的 Cookie 内容,如果与上次不同则触发回调。
56
+ */
27
57
  private handleChange = (): void => {
28
58
  const newContent = this.cookieReader.readCookie();
29
59
  if (newContent !== this.lastContent) {
@@ -33,6 +63,9 @@ export class CookieWatcher {
33
63
  }
34
64
  };
35
65
 
66
+ /**
67
+ * 启动文件监听
68
+ */
36
69
  start(): void {
37
70
  if (this.options.autoCreateFile) {
38
71
  this.cookieReader.ensureCookieFile();
@@ -52,7 +85,8 @@ export class CookieWatcher {
52
85
  },
53
86
  });
54
87
 
55
- // "add" covers atomic replace (unlink + rename) used by some editors; "change" covers in-place writes
88
+ // "add" covers atomic replace (unlink + rename) used by some editors;
89
+ // "change" covers in-place writes
56
90
  this.watcher.on('change', this.handleChange);
57
91
  this.watcher.on('add', this.handleChange);
58
92
  this.watcher.on('error', (error) => {
@@ -63,6 +97,9 @@ export class CookieWatcher {
63
97
  }
64
98
  }
65
99
 
100
+ /**
101
+ * 停止文件监听
102
+ */
66
103
  stop(): void {
67
104
  if (this.watcher) {
68
105
  this.watcher.close();
@@ -71,11 +108,23 @@ export class CookieWatcher {
71
108
  }
72
109
  }
73
110
 
111
+ /**
112
+ * 获取当前 Cookie 值
113
+ * @returns 当前 Cookie 字符串
114
+ */
74
115
  getCurrentCookie(): string {
75
116
  return this.lastContent;
76
117
  }
77
118
  }
78
119
 
120
+ /**
121
+ * 创建并启动 Cookie 文件监听器
122
+ *
123
+ * @param cookieFile - Cookie 文件路径
124
+ * @param onCookieChange - Cookie 变化回调函数
125
+ * @param onError - 错误回调函数(可选)
126
+ * @returns CookieWatcher 实例
127
+ */
79
128
  export function watchCookieFile(
80
129
  cookieFile: string,
81
130
  onCookieChange: (cookie: string) => void,
@@ -1,10 +1,17 @@
1
1
  /**
2
- * 环境检测工具函数
3
- * 用于智能判断当前是否为生产构建环境
2
+ * 环境检测工具模块
3
+ *
4
+ * 提供智能环境检测功能,用于判断当前是否为生产构建环境,
5
+ * 从而决定是否启用文件监听等开发环境特性。
6
+ *
7
+ * @module env-detector
4
8
  */
5
9
 
6
10
  /**
7
11
  * 判断环境变量值是否表示生产环境
12
+ *
13
+ * @param value - 环境变量值
14
+ * @returns 是否为生产环境值
8
15
  */
9
16
  export function isProductionValue(value: string): boolean {
10
17
  const productionValues = [
@@ -1,3 +1,10 @@
1
+ /**
2
+ * 工具模块导出文件
3
+ *
4
+ * 包含 Cookie 读取、文件监听和环境检测等核心工具函数。
5
+ *
6
+ * @module utils
7
+ */
1
8
  export * from './cookie-reader';
2
9
  export * from './cookie-watcher';
3
10
  export * from './env-detector';
@@ -1,98 +0,0 @@
1
- import type { Plugin } from 'vite';
2
- import { viteAutoProxyCookie, type ViteAutoProxyCookiePluginOptions } from './vite-plugin';
3
- import { viteDevProxyCookie, type ViteDevProxyCookieOptions } from './vite-cookie-plugin';
4
-
5
- let viteVersion: string = '';
6
- let majorVersion: number | null = null;
7
-
8
- function detectViteVersion(): number {
9
- if (majorVersion !== null) {
10
- return majorVersion;
11
- }
12
-
13
- try {
14
- const pkg = require('vite/package.json');
15
- viteVersion = pkg.version;
16
- majorVersion = parseInt(viteVersion.split('.')[0], 10);
17
- } catch {
18
- majorVersion = 5;
19
- }
20
-
21
- return majorVersion;
22
- }
23
-
24
- export interface UnifiedProxyCookieOptions {
25
- cookieFile: string;
26
- target?: string;
27
- debug?: boolean;
28
- autoRestart?: boolean;
29
- restartMarkerFile?: string;
30
- proxyMap?: Record<string, string>;
31
- ignorePaths?: string[];
32
- includePaths?: string[];
33
- onCookieChange?: (cookie: string) => void;
34
- mode?: 'auto' | 'proxy' | 'cookie';
35
- /**
36
- * 是否监听文件变化
37
- * - true: 始终监听
38
- * - false: 从不监听
39
- * - 'auto': 根据环境自动判断(默认)
40
- * @default 'auto'
41
- */
42
- watch?: boolean | 'auto';
43
- /**
44
- * 是否为开发环境(优先级最高)
45
- * 设置此参数后,将直接决定是否启用文件监听:
46
- * - true: 启用监听(开发模式)
47
- * - false: 禁用监听(生产模式)
48
- *
49
- * 使用示例: isDev: process.env.NODE_ENV === 'development'
50
- */
51
- isDev?: boolean;
52
- }
53
-
54
- export function createDevProxyCookie(options: UnifiedProxyCookieOptions): Plugin {
55
- const {
56
- mode = 'auto',
57
- watch = 'auto',
58
- isDev,
59
- ...restOptions
60
- } = options;
61
-
62
- const version = detectViteVersion();
63
-
64
- if (options.debug) {
65
- console.log(`[dev-proxy-cookie] Detected Vite ${version}.x`);
66
- }
67
-
68
- if (mode === 'cookie' || (mode === 'auto' && !options.target)) {
69
- return viteDevProxyCookie({
70
- cookieFile: options.cookieFile,
71
- debug: options.debug,
72
- onCookieChange: options.onCookieChange,
73
- watch,
74
- isDev,
75
- });
76
- }
77
-
78
- const pluginOptions: ViteAutoProxyCookiePluginOptions = {
79
- cookieFile: options.cookieFile,
80
- target: options.target!,
81
- debug: options.debug,
82
- autoRestart: options.autoRestart ?? true,
83
- restartMarkerFile: options.restartMarkerFile,
84
- proxyMap: options.proxyMap,
85
- ignorePaths: options.ignorePaths,
86
- };
87
-
88
- return viteAutoProxyCookie(pluginOptions);
89
- }
90
-
91
- export function getViteVersion(): string | null {
92
- detectViteVersion();
93
- return viteVersion;
94
- }
95
-
96
- export function getViteMajorVersion(): number {
97
- return detectViteVersion();
98
- }
@@ -1,94 +0,0 @@
1
- import type { Plugin, ViteDevServer } from 'vite';
2
- import { CookieReader, watchCookieFile, shouldEnableWatch } from '../utils';
3
-
4
- export interface ViteDevProxyCookieOptions {
5
- cookieFile: string;
6
- debug?: boolean;
7
- onCookieChange?: (cookie: string) => void;
8
- /**
9
- * 是否监听文件变化
10
- * - true: 始终监听
11
- * - false: 从不监听
12
- * - 'auto': 根据环境自动判断(默认)
13
- * @default 'auto'
14
- */
15
- watch?: boolean | 'auto';
16
- /**
17
- * 是否为开发环境(优先级最高)
18
- * 设置此参数后,将直接决定是否启用文件监听:
19
- * - true: 启用监听(开发模式)
20
- * - false: 禁用监听(生产模式)
21
- *
22
- * 使用示例: isDev: process.env.NODE_ENV === 'development'
23
- */
24
- isDev?: boolean;
25
- }
26
-
27
- export function viteDevProxyCookie(options: ViteDevProxyCookieOptions): Plugin {
28
- const { cookieFile, debug = false, onCookieChange, watch = 'auto', isDev } = options;
29
- let watcher: any = null;
30
- let currentCookie: string = '';
31
-
32
- const cookieReader = new CookieReader({ cookieFile });
33
-
34
- return {
35
- name: 'vite-dev-proxy-cookie',
36
- apply: 'serve',
37
-
38
- configureServer(server: ViteDevServer) {
39
- currentCookie = cookieReader.readCookie();
40
- if (debug) {
41
- console.log('[vite-dev-proxy-cookie] Initial cookie loaded');
42
- }
43
-
44
- const middlewares = server.middlewares ||
45
- (server as any)._middlewares ||
46
- (server as any).app;
47
-
48
- if (middlewares && typeof middlewares.use === 'function') {
49
- middlewares.use((req: any, _res: any, next: any) => {
50
- if (currentCookie && req.url?.startsWith('/')) {
51
- req.headers = req.headers || {};
52
- req.headers['cookie'] = currentCookie;
53
- }
54
- next();
55
- });
56
- } else {
57
- console.warn('[vite-dev-proxy-cookie] Could not access middleware stack, cookie injection disabled');
58
- }
59
-
60
- // 判断是否应该启用监听
61
- // isDev 参数优先级最高
62
- let shouldWatch: boolean;
63
-
64
- if (isDev !== undefined) {
65
- shouldWatch = isDev;
66
- if (debug) {
67
- console.log(`[vite-dev-proxy-cookie] isDev=${isDev}, ${shouldWatch ? 'enabling' : 'disabling'} watch`);
68
- }
69
- } else {
70
- shouldWatch = shouldEnableWatch(watch, [], debug, '[vite-dev-proxy-cookie]');
71
- }
72
-
73
- if (shouldWatch) {
74
- watcher = watchCookieFile(
75
- cookieFile,
76
- (newCookie) => {
77
- currentCookie = newCookie;
78
- onCookieChange?.(newCookie);
79
- console.log('[vite-dev-proxy-cookie] Cookie changed, please restart server for full effect');
80
- },
81
- (error) => {
82
- console.error('[vite-dev-proxy-cookie] Watch error:', error.message);
83
- }
84
- );
85
- } else if (debug) {
86
- console.log('[vite-dev-proxy-cookie] File watch disabled');
87
- }
88
- },
89
-
90
- closeBundle() {
91
- watcher?.stop();
92
- },
93
- };
94
- }