@gylautorun/dev-proxy-cookie 1.0.0 → 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/dist/index.js CHANGED
@@ -39,8 +39,11 @@ __export(index_exports, {
39
39
  createDevProxyCookie: () => createDevProxyCookie,
40
40
  createFileCookieGetter: () => createFileCookieGetter,
41
41
  createVueProxyConfig: () => createVueProxyConfig,
42
+ detectProductionEnvironment: () => detectProductionEnvironment,
42
43
  getViteMajorVersion: () => getViteMajorVersion,
43
44
  getViteVersion: () => getViteVersion,
45
+ isProductionValue: () => isProductionValue,
46
+ shouldEnableWatch: () => shouldEnableWatch,
44
47
  viteAutoProxyCookie: () => viteAutoProxyCookie,
45
48
  viteDevProxyCookie: () => viteDevProxyCookie,
46
49
  watchCookieFile: () => watchCookieFile
@@ -160,6 +163,102 @@ function watchCookieFile(cookieFile, onCookieChange, onError) {
160
163
  return watcher;
161
164
  }
162
165
 
166
+ // src/utils/env-detector.ts
167
+ function isProductionValue(value) {
168
+ const productionValues = [
169
+ "production",
170
+ // 生产环境
171
+ "prod",
172
+ // 生产环境
173
+ "prd",
174
+ // 生产环境
175
+ "release",
176
+ // 发布环境
177
+ "staging",
178
+ // 预发布环境
179
+ "uat"
180
+ // 预发布环境
181
+ ];
182
+ return productionValues.includes(value.toLowerCase().trim());
183
+ }
184
+ function detectProductionEnvironment(customEnvs = [], debug = false, loggerPrefix = "[env-detector]") {
185
+ const env = process.env;
186
+ if (customEnvs.length > 0) {
187
+ for (const envName of customEnvs) {
188
+ const envValue = env[envName];
189
+ if (envValue && isProductionValue(envValue)) {
190
+ if (debug) {
191
+ console.log(`${loggerPrefix} Detected production via custom env: ${envName}=${envValue}`);
192
+ }
193
+ return true;
194
+ }
195
+ }
196
+ }
197
+ const commonEnvNames = [
198
+ "NODE_ENV",
199
+ "BUILD_MODE",
200
+ "VUE_APP_ENV",
201
+ "VITE_NODE_ENV",
202
+ "WEBPACK_MODE",
203
+ "CI_ENV",
204
+ "APP_ENV",
205
+ "ENV",
206
+ "DEPLOY_ENV",
207
+ "RUN_MODE"
208
+ ];
209
+ for (const envName of commonEnvNames) {
210
+ const envValue = env[envName];
211
+ if (envValue && isProductionValue(envValue)) {
212
+ if (debug) {
213
+ console.log(`${loggerPrefix} Detected production via env: ${envName}=${envValue}`);
214
+ }
215
+ return true;
216
+ }
217
+ }
218
+ if (env.CI === "true" || env.CI === "1" || env.CI === "yes") {
219
+ if (debug) {
220
+ console.log(`${loggerPrefix} Detected production via CI env`);
221
+ }
222
+ return true;
223
+ }
224
+ if (env.npm_lifecycle_event) {
225
+ const lifecycleEvent = env.npm_lifecycle_event.toLowerCase();
226
+ if (lifecycleEvent.includes("build") || lifecycleEvent.includes("prod") || lifecycleEvent.includes("prd") || lifecycleEvent.includes("release")) {
227
+ if (debug) {
228
+ console.log(`${loggerPrefix} Detected production via lifecycle event: ${env.npm_lifecycle_event}`);
229
+ }
230
+ return true;
231
+ }
232
+ }
233
+ const processArgs = process.argv.join("").toLowerCase();
234
+ if (processArgs.includes("build") || processArgs.includes("production") || processArgs.includes("--mode=production") || processArgs.includes("--prod") || processArgs.includes("--release")) {
235
+ if (debug) {
236
+ console.log(`${loggerPrefix} Detected production via process arguments`);
237
+ }
238
+ return true;
239
+ }
240
+ return false;
241
+ }
242
+ function shouldEnableWatch(watch, customEnvs = [], debug = false, loggerPrefix = "[env-detector]") {
243
+ if (typeof watch === "boolean") {
244
+ if (debug && !watch) {
245
+ console.log(`${loggerPrefix} Watch disabled by user setting`);
246
+ }
247
+ return watch;
248
+ }
249
+ const isProduction = detectProductionEnvironment(customEnvs, debug, loggerPrefix);
250
+ if (isProduction) {
251
+ if (debug) {
252
+ console.log(`${loggerPrefix} Auto-detected production mode - disabling watch`);
253
+ }
254
+ return false;
255
+ }
256
+ if (debug) {
257
+ console.log(`${loggerPrefix} Auto-detected development mode - enabling watch`);
258
+ }
259
+ return true;
260
+ }
261
+
163
262
  // src/proxy/apply-dev-cookie-header.ts
164
263
  function applyDevCookieHeader(proxyReq, cookie) {
165
264
  if (!cookie) return;
@@ -432,13 +531,29 @@ var AutoProxyCookie = class {
432
531
  }
433
532
  }
434
533
  startFileWatch() {
435
- this.watcher = watchCookieFile(
436
- this.options.cookieFile,
437
- this.handleCookieChange,
438
- (error) => {
439
- this.log("error", "[AutoProxyCookie] File watch error:", error.message);
534
+ let shouldWatch;
535
+ if (this.options.isDev !== void 0) {
536
+ shouldWatch = this.options.isDev;
537
+ if (this.options.debug) {
538
+ console.log(`[AutoProxyCookie] isDev=${this.options.isDev}, ${shouldWatch ? "enabling" : "disabling"} watch`);
440
539
  }
441
- );
540
+ } else {
541
+ shouldWatch = true;
542
+ if (this.options.debug) {
543
+ console.log("[AutoProxyCookie] Default behavior: enabling watch (dev mode)");
544
+ }
545
+ }
546
+ if (shouldWatch) {
547
+ this.watcher = watchCookieFile(
548
+ this.options.cookieFile,
549
+ this.handleCookieChange,
550
+ (error) => {
551
+ this.log("error", "[AutoProxyCookie] File watch error:", error.message);
552
+ }
553
+ );
554
+ } else if (this.options.debug) {
555
+ console.log("[AutoProxyCookie] File watch disabled");
556
+ }
442
557
  }
443
558
  stop() {
444
559
  if (this.watcher) {
@@ -463,6 +578,7 @@ function createAutoProxyCookie(options) {
463
578
  function viteAutoProxyCookie(options) {
464
579
  const {
465
580
  name = "vite-auto-proxy-cookie",
581
+ isDev,
466
582
  ...autoProxyOptions
467
583
  } = options;
468
584
  let autoProxy = null;
@@ -473,7 +589,8 @@ function viteAutoProxyCookie(options) {
473
589
  autoProxy = createAutoProxyCookie({
474
590
  ...autoProxyOptions,
475
591
  debug: options.debug ?? false,
476
- autoRestart: options.autoRestart ?? true
592
+ autoRestart: options.autoRestart ?? true,
593
+ isDev
477
594
  });
478
595
  try {
479
596
  await autoProxy.setup(server);
@@ -492,7 +609,7 @@ function viteAutoProxyCookie(options) {
492
609
 
493
610
  // src/proxy/vite-cookie-plugin.ts
494
611
  function viteDevProxyCookie(options) {
495
- const { cookieFile, debug = false, onCookieChange } = options;
612
+ const { cookieFile, debug = false, onCookieChange, watch = "auto", isDev } = options;
496
613
  let watcher = null;
497
614
  let currentCookie = "";
498
615
  const cookieReader = new CookieReader({ cookieFile });
@@ -516,17 +633,30 @@ function viteDevProxyCookie(options) {
516
633
  } else {
517
634
  console.warn("[vite-dev-proxy-cookie] Could not access middleware stack, cookie injection disabled");
518
635
  }
519
- watcher = watchCookieFile(
520
- cookieFile,
521
- (newCookie) => {
522
- currentCookie = newCookie;
523
- onCookieChange?.(newCookie);
524
- console.log("[vite-dev-proxy-cookie] Cookie changed, please restart server for full effect");
525
- },
526
- (error) => {
527
- console.error("[vite-dev-proxy-cookie] Watch error:", error.message);
636
+ let shouldWatch;
637
+ if (isDev !== void 0) {
638
+ shouldWatch = isDev;
639
+ if (debug) {
640
+ console.log(`[vite-dev-proxy-cookie] isDev=${isDev}, ${shouldWatch ? "enabling" : "disabling"} watch`);
528
641
  }
529
- );
642
+ } else {
643
+ shouldWatch = shouldEnableWatch(watch, [], debug, "[vite-dev-proxy-cookie]");
644
+ }
645
+ if (shouldWatch) {
646
+ watcher = watchCookieFile(
647
+ cookieFile,
648
+ (newCookie) => {
649
+ currentCookie = newCookie;
650
+ onCookieChange?.(newCookie);
651
+ console.log("[vite-dev-proxy-cookie] Cookie changed, please restart server for full effect");
652
+ },
653
+ (error) => {
654
+ console.error("[vite-dev-proxy-cookie] Watch error:", error.message);
655
+ }
656
+ );
657
+ } else if (debug) {
658
+ console.log("[vite-dev-proxy-cookie] File watch disabled");
659
+ }
530
660
  },
531
661
  closeBundle() {
532
662
  watcher?.stop();
@@ -569,9 +699,23 @@ function createVueProxyConfig(target, options = {}) {
569
699
  return config;
570
700
  }
571
701
  function createFileCookieGetter(cookieFile, options = {}) {
572
- const { watch = true, debug = false } = options;
702
+ const {
703
+ watch = "auto",
704
+ debug = false,
705
+ productionEnvs = [],
706
+ isDev
707
+ } = options;
573
708
  const reader = new CookieReader({ cookieFile: path4.resolve(cookieFile) });
574
- if (watch) {
709
+ let shouldWatch;
710
+ if (isDev !== void 0) {
711
+ shouldWatch = isDev;
712
+ if (debug) {
713
+ console.log(`[CookieFile] isDev=${isDev}, ${shouldWatch ? "enabling" : "disabling"} watch`);
714
+ }
715
+ } else {
716
+ shouldWatch = shouldEnableWatch(watch, productionEnvs, debug, "[CookieFile]");
717
+ }
718
+ if (shouldWatch) {
575
719
  watchCookieFile(
576
720
  path4.resolve(cookieFile),
577
721
  (newCookie) => {
@@ -583,6 +727,8 @@ function createFileCookieGetter(cookieFile, options = {}) {
583
727
  console.error("[CookieFile] Watch error:", error.message);
584
728
  }
585
729
  );
730
+ } else if (debug) {
731
+ console.log("[CookieFile] File watch disabled");
586
732
  }
587
733
  return () => reader.readCookie();
588
734
  }
@@ -644,6 +790,8 @@ function detectViteVersion() {
644
790
  function createDevProxyCookie(options) {
645
791
  const {
646
792
  mode = "auto",
793
+ watch = "auto",
794
+ isDev,
647
795
  ...restOptions
648
796
  } = options;
649
797
  const version = detectViteVersion();
@@ -654,7 +802,9 @@ function createDevProxyCookie(options) {
654
802
  return viteDevProxyCookie({
655
803
  cookieFile: options.cookieFile,
656
804
  debug: options.debug,
657
- onCookieChange: options.onCookieChange
805
+ onCookieChange: options.onCookieChange,
806
+ watch,
807
+ isDev
658
808
  });
659
809
  }
660
810
  const pluginOptions = {
@@ -686,8 +836,11 @@ function getViteMajorVersion() {
686
836
  createDevProxyCookie,
687
837
  createFileCookieGetter,
688
838
  createVueProxyConfig,
839
+ detectProductionEnvironment,
689
840
  getViteMajorVersion,
690
841
  getViteVersion,
842
+ isProductionValue,
843
+ shouldEnableWatch,
691
844
  viteAutoProxyCookie,
692
845
  viteDevProxyCookie,
693
846
  watchCookieFile
package/dist/index.min.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var U=Object.create;var m=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty;var B=(r,e)=>{for(var o in e)m(r,o,{get:e[o],enumerable:!0})},M=(r,e,o,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of j(e))!$.call(r,i)&&i!==o&&m(r,i,{get:()=>e[i],enumerable:!(t=T(e,i))||t.enumerable});return r};var u=(r,e,o)=>(o=r!=null?U(_(r)):{},M(e||!r||!r.__esModule?m(o,"default",{value:r,enumerable:!0}):o,r)),G=r=>M(m({},"__esModule",{value:!0}),r);var Y={};B(Y,{AutoProxyCookie:()=>C,CookieReader:()=>g,CookieWatcher:()=>w,createAutoProxyConfig:()=>z,createAutoProxyCookie:()=>R,createCookieGetter:()=>N,createDevProxyCookie:()=>X,createFileCookieGetter:()=>J,createVueProxyConfig:()=>A,getViteMajorVersion:()=>Q,getViteVersion:()=>K,viteAutoProxyCookie:()=>S,viteDevProxyCookie:()=>b,watchCookieFile:()=>k});module.exports=G(Y);var D=u(require("http")),V=u(require("fs")),H=u(require("path")),q=u(require("http-proxy"));var p=u(require("fs")),x=u(require("path")),g=class{constructor(e){this.options={encoding:"utf-8",...e}}readCookie(){try{let e=x.resolve(this.options.cookieFile);return p.existsSync(e)?p.readFileSync(e,this.options.encoding||"utf-8").split(`
2
- `).map(s=>s.trim()).filter(s=>s&&!s.startsWith("#")).join("; "):""}catch{return""}}ensureCookieFile(){let e=x.resolve(this.options.cookieFile),o=x.dirname(e);p.existsSync(o)||p.mkdirSync(o,{recursive:!0}),p.existsSync(e)||p.writeFileSync(e,"")}};function N(r){let e=new g({cookieFile:r});return()=>e.readCookie()}var W=u(require("path")),I=u(require("chokidar"));var w=class{constructor(e){this.watcher=null;this.lastContent="";this.handleChange=()=>{let e=this.cookieReader.readCookie();e!==this.lastContent&&(this.lastContent=e,this.options.onCookieChange(e),console.log(`[CookieWatcher] Cookie updated from file: ${this.options.cookieFile}`))};this.options={autoCreateFile:!0,...e},this.cookieReader=new g({cookieFile:e.cookieFile})}start(){this.options.autoCreateFile&&this.cookieReader.ensureCookieFile();let e=W.resolve(this.options.cookieFile);this.lastContent=this.cookieReader.readCookie(),console.log(`[CookieWatcher] Started watching: ${e}`);try{this.watcher=I.default.watch(e,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}}),this.watcher.on("change",this.handleChange),this.watcher.on("add",this.handleChange),this.watcher.on("error",o=>{this.options.onError?.(o)})}catch(o){this.options.onError?.(o)}}stop(){this.watcher&&(this.watcher.close(),this.watcher=null,console.log(`[CookieWatcher] Stopped watching: ${this.options.cookieFile}`))}getCurrentCookie(){return this.lastContent}};function k(r,e,o){let t=new w({cookieFile:r,onCookieChange:e,onError:o});return t.start(),t}function v(r,e){e&&(r.removeHeader("cookie"),r.removeHeader("Cookie"),r.setHeader("Cookie",e))}var C=class{constructor(e){this.currentCookie="";this.server=null;this.proxyServer=null;this.watcher=null;this.handleCookieChange=e=>{if(e!==this.currentCookie&&(this.currentCookie=e,this.log("info","[AutoProxyCookie] Cookie updated:",e?"(has cookie)":"(empty)"),this.options.autoRestart&&this.options.restartMarkerFile)){let o=H.resolve(this.options.restartMarkerFile);V.writeFileSync(o,JSON.stringify({timestamp:Date.now(),cookie:e},null,2)),this.log("info","[AutoProxyCookie] Restart marker written to:",o),this.log("info","[AutoProxyCookie] Please restart the dev server for changes to take effect")}};this.handleOnProxyReq=(e,o,t,i)=>{if(this.currentCookie&&v(e,this.currentCookie),this.log("debug","[AutoProxyCookie] Proxy Request:",o.method,o.url),this.options.hooks.onProxyReq)try{this.options.hooks.onProxyReq(e,o,t)}catch(s){this.log("error","[AutoProxyCookie] onProxyReq hook error:",s.message)}};this.handleOnProxyRes=(e,o,t)=>{let i=["Content-Type","Content-Length","Authorization","Set-Cookie","X-Requested-With","Access-Control-Allow-Origin","Access-Control-Allow-Credentials"];if(t.setHeader("Access-Control-Allow-Origin","*"),t.setHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE, OPTIONS"),t.setHeader("Access-Control-Allow-Headers",i.join(",")),t.setHeader("Access-Control-Allow-Credentials","true"),this.log("debug","[AutoProxyCookie] Proxy Response:",o.url,e.statusCode),this.options.hooks.onProxyRes)try{this.options.hooks.onProxyRes(e,o,t)}catch(s){this.log("error","[AutoProxyCookie] onProxyRes hook error:",s.message)}};this.handleOnError=(e,o,t)=>{if(this.log("error","[AutoProxyCookie] Proxy Error:",e.message),this.log("error","[AutoProxyCookie] URL:",o.url),t instanceof D.ServerResponse&&!t.headersSent&&(t.writeHead(503,{"Content-Type":"application/json; charset=utf-8"}),t.end(JSON.stringify({success:!1,message:"\u670D\u52A1\u6682\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",error:e.message}))),this.options.hooks.onError)try{this.options.hooks.onError(e,o,t)}catch(i){this.log("error","[AutoProxyCookie] onError hook error:",i.message)}};this.handleOnWsError=(e,o,t)=>{if(this.log("error","[AutoProxyCookie] WebSocket Proxy Error:",e.message),this.log("error","[AutoProxyCookie] WebSocket URL:",o.url),t&&t.close(),this.options.hooks.onWsError)try{this.options.hooks.onWsError(e,o,t)}catch(i){this.log("error","[AutoProxyCookie] onWsError hook error:",i.message)}};let t={...e,hooks:{...{onProxyReq:()=>{},onProxyRes:()=>{},onError:()=>{},onWsError:()=>{}},...e.hooks||{}}};this.options={debug:!1,autoRestart:!1,restartMarkerFile:".cookie-restart-marker",proxyMap:{},ignorePaths:[],ws:!0,changeOrigin:!0,secure:!1,followRedirects:!0,autoRewrite:!1,protocolRewrite:void 0,logLevel:"info",cookieDomainRewrite:"*",cookiePathRewrite:!1,headers:{},...t},this.cookieReader=new g({cookieFile:e.cookieFile})}getProxyUrl(e){let o=e.url?.split("?")[0]||"/",t=this.options.proxyMap||{};for(let[i,s]of Object.entries(t))if(o.startsWith(i))return s;return this.options.target}isIgnoredPath(e){return(this.options.ignorePaths||[]).some(t=>e.startsWith(t))}log(e,...o){let t={debug:0,info:1,warn:2,error:3},i=t[this.options.logLevel||"info"];t[e]>=i&&(e==="error"?console.error(...o):e==="warn"?console.warn(...o):console.log(...o))}createProxyOptions(e){let{ws:o,changeOrigin:t,secure:i,followRedirects:s,autoRewrite:c,protocolRewrite:l,cookieDomainRewrite:a,cookiePathRewrite:n,headers:h}=this.options;return{target:e,ws:o,changeOrigin:t,secure:i,followRedirects:s,autoRewrite:c,protocolRewrite:l,cookieDomainRewrite:a,cookiePathRewrite:n,headers:{...h},ignorePath:!1}}async setup(e){this.server=e,this.currentCookie=this.cookieReader.readCookie();try{let o={target:this.options.target,changeOrigin:this.options.changeOrigin,secure:this.options.secure,followRedirects:this.options.followRedirects,autoRewrite:this.options.autoRewrite,protocolRewrite:this.options.protocolRewrite,cookieDomainRewrite:this.options.cookieDomainRewrite,cookiePathRewrite:this.options.cookiePathRewrite,ws:this.options.ws};this.proxyServer=q.default.createProxyServer(o),this.proxyServer.on("proxyReq",this.handleOnProxyReq),this.proxyServer.on("proxyRes",this.handleOnProxyRes),this.proxyServer.on("error",this.handleOnError),this.options.ws&&this.proxyServer.on("wsError",this.handleOnWsError),this.log("info","[AutoProxyCookie] Proxy server created with WebSocket support")}catch(o){this.log("warn","[AutoProxyCookie] http-proxy create failed, using basic mode:",o.message)}e.middlewares.use((o,t,i)=>{let s=new URL(o.url||"/","http://localhost").pathname;if(this.isIgnoredPath(s)){i();return}if(this.currentCookie=this.cookieReader.readCookie(),this.proxyServer){let c=this.getProxyUrl(o);(this.options.debug||this.options.logLevel==="debug")&&this.log("info",`[AutoProxyCookie] ${s} -> ${c}`);let l=this.createProxyOptions(c);try{this.proxyServer.web(o,t,l)}catch(a){this.log("error","[AutoProxyCookie] Proxy web error:",a.message),i(a)}}else i()}),this.options.ws&&this.server.httpServer&&this.proxyServer&&(this.server.httpServer.on("upgrade",(o,t,i)=>{let s=new URL(o.url||"/","http://localhost").pathname;if(this.isIgnoredPath(s)){t.destroy();return}let c=this.getProxyUrl(o);this.proxyServer?.ws(o,t,i,{target:c,ws:!0,changeOrigin:this.options.changeOrigin,secure:this.options.secure})}),this.log("info","[AutoProxyCookie] WebSocket upgrade handler registered")),this.startFileWatch(),this.log("info","[AutoProxyCookie] Auto-proxy middleware enabled"),this.log("info","[AutoProxyCookie] Target:",this.options.target),this.log("info","[AutoProxyCookie] Cookie file:",this.options.cookieFile),this.options.autoRestart&&this.log("info","[AutoProxyCookie] Auto-restart enabled"),this.options.ws&&this.log("info","[AutoProxyCookie] WebSocket support enabled")}startFileWatch(){this.watcher=k(this.options.cookieFile,this.handleCookieChange,e=>{this.log("error","[AutoProxyCookie] File watch error:",e.message)})}stop(){this.watcher&&(this.watcher.stop(),this.watcher=null),this.proxyServer&&(this.proxyServer.close(),this.proxyServer=null),this.log("info","[AutoProxyCookie] Stopped")}getCurrentCookie(){return this.currentCookie}};function R(r){return new C(r)}function S(r){let{name:e="vite-auto-proxy-cookie",...o}=r,t=null;return{name:e,apply:"serve",async configureServer(i){t=R({...o,debug:r.debug??!1,autoRestart:r.autoRestart??!0});try{await t.setup(i)}catch(s){console.error("[vite-auto-proxy-cookie] Failed to setup proxy:",s),r.debug&&console.log("[vite-auto-proxy-cookie] Falling back to middleware mode")}},closeBundle(){t?.stop()}}}function b(r){let{cookieFile:e,debug:o=!1,onCookieChange:t}=r,i=null,s="",c=new g({cookieFile:e});return{name:"vite-dev-proxy-cookie",apply:"serve",configureServer(l){s=c.readCookie(),o&&console.log("[vite-dev-proxy-cookie] Initial cookie loaded");let a=l.middlewares||l._middlewares||l.app;a&&typeof a.use=="function"?a.use((n,h,d)=>{s&&n.url?.startsWith("/")&&(n.headers=n.headers||{},n.headers.cookie=s),d()}):console.warn("[vite-dev-proxy-cookie] Could not access middleware stack, cookie injection disabled"),i=k(e,n=>{s=n,t?.(n),console.log("[vite-dev-proxy-cookie] Cookie changed, please restart server for full effect")},n=>{console.error("[vite-dev-proxy-cookie] Watch error:",n.message)})},closeBundle(){i?.stop()}}}var O=u(require("path"));function A(r,e={}){let{getCookie:o,debug:t=!1,headers:i={},ws:s=!1,changeOrigin:c=!0,secure:l=!1,onError:a}=e;return{ws:s,target:r,changeOrigin:c,secure:l,headers:i,onProxyReq:(h,d)=>{let f=o?o():"";if(f&&v(h,f),t){let y=d.url||"/";console.log("[Proxy Request]",y,d.method,f?"(with cookie)":"(no cookie)")}},onError:a||(h=>{console.error(`
3
- [Proxy Error]`,h.message)})}}function J(r,e={}){let{watch:o=!0,debug:t=!1}=e,i=new g({cookieFile:O.resolve(r)});return o&&k(O.resolve(r),s=>{t&&console.log("[CookieFile] Updated:",s?"(has cookie)":"(empty)")},s=>{console.error("[CookieFile] Watch error:",s.message)}),()=>i.readCookie()}function z(r){let{target:e,ignorePaths:o=[],includePaths:t=[],additionalProxies:i={},getCookie:s,debug:c,headers:l}=r,a={};if(t.length>0)for(let n of t)a[n]=A(e,{getCookie:s,debug:c,headers:l});else{let n={ws:!1,target:e,changeOrigin:!0,secure:!1,headers:l,onProxyReq:(h,d)=>{let f=d.url||"/";if(o.some(L=>f.startsWith(L)))return;let y=s?s():"";y&&v(h,y),c&&console.log("[Proxy Request]",f,d.method,y?"(with cookie)":"(no cookie)")},onError:h=>{console.error(`
4
- [Proxy Error]`,h.message)}};a["/"]=n}for(let[n,h]of Object.entries(i))a[n]=A(h,{getCookie:s,debug:c,headers:l});return a}var E="",P=null;function F(){if(P!==null)return P;try{E=require("vite/package.json").version,P=parseInt(E.split(".")[0],10)}catch{P=5}return P}function X(r){let{mode:e="auto",...o}=r,t=F();if(r.debug&&console.log(`[dev-proxy-cookie] Detected Vite ${t}.x`),e==="cookie"||e==="auto"&&!r.target)return b({cookieFile:r.cookieFile,debug:r.debug,onCookieChange:r.onCookieChange});let i={cookieFile:r.cookieFile,target:r.target,debug:r.debug,autoRestart:r.autoRestart??!0,restartMarkerFile:r.restartMarkerFile,proxyMap:r.proxyMap,ignorePaths:r.ignorePaths};return S(i)}function K(){return F(),E}function Q(){return F()}0&&(module.exports={AutoProxyCookie,CookieReader,CookieWatcher,createAutoProxyConfig,createAutoProxyCookie,createCookieGetter,createDevProxyCookie,createFileCookieGetter,createVueProxyConfig,getViteMajorVersion,getViteVersion,viteAutoProxyCookie,viteDevProxyCookie,watchCookieFile});
1
+ "use strict";var U=Object.create;var w=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var J=(t,e)=>{for(var o in e)w(t,o,{get:e[o],enumerable:!0})},W=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of j(e))!G.call(t,n)&&n!==o&&w(t,n,{get:()=>e[n],enumerable:!(r=T(e,n))||r.enumerable});return t};var f=(t,e,o)=>(o=t!=null?U(B(t)):{},W(e||!t||!t.__esModule?w(o,"default",{value:t,enumerable:!0}):o,t)),z=t=>W(w({},"__esModule",{value:!0}),t);var oe={};J(oe,{AutoProxyCookie:()=>m,CookieReader:()=>u,CookieWatcher:()=>R,createAutoProxyConfig:()=>Y,createAutoProxyCookie:()=>O,createCookieGetter:()=>K,createDevProxyCookie:()=>Q,createFileCookieGetter:()=>X,createVueProxyConfig:()=>D,detectProductionEnvironment:()=>_,getViteMajorVersion:()=>ee,getViteVersion:()=>Z,isProductionValue:()=>S,shouldEnableWatch:()=>x,viteAutoProxyCookie:()=>E,viteDevProxyCookie:()=>A,watchCookieFile:()=>k});module.exports=z(oe);var H=f(require("http")),L=f(require("fs")),q=f(require("path")),N=f(require("http-proxy"));var d=f(require("fs")),v=f(require("path")),u=class{constructor(e){this.options={encoding:"utf-8",...e}}readCookie(){try{let e=v.resolve(this.options.cookieFile);return d.existsSync(e)?d.readFileSync(e,this.options.encoding||"utf-8").split(`
2
+ `).map(i=>i.trim()).filter(i=>i&&!i.startsWith("#")).join("; "):""}catch{return""}}ensureCookieFile(){let e=v.resolve(this.options.cookieFile),o=v.dirname(e);d.existsSync(o)||d.mkdirSync(o,{recursive:!0}),d.existsSync(e)||d.writeFileSync(e,"")}};function K(t){let e=new u({cookieFile:t});return()=>e.readCookie()}var I=f(require("path")),$=f(require("chokidar"));var R=class{constructor(e){this.watcher=null;this.lastContent="";this.handleChange=()=>{let e=this.cookieReader.readCookie();e!==this.lastContent&&(this.lastContent=e,this.options.onCookieChange(e),console.log(`[CookieWatcher] Cookie updated from file: ${this.options.cookieFile}`))};this.options={autoCreateFile:!0,...e},this.cookieReader=new u({cookieFile:e.cookieFile})}start(){this.options.autoCreateFile&&this.cookieReader.ensureCookieFile();let e=I.resolve(this.options.cookieFile);this.lastContent=this.cookieReader.readCookie(),console.log(`[CookieWatcher] Started watching: ${e}`);try{this.watcher=$.default.watch(e,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}}),this.watcher.on("change",this.handleChange),this.watcher.on("add",this.handleChange),this.watcher.on("error",o=>{this.options.onError?.(o)})}catch(o){this.options.onError?.(o)}}stop(){this.watcher&&(this.watcher.close(),this.watcher=null,console.log(`[CookieWatcher] Stopped watching: ${this.options.cookieFile}`))}getCurrentCookie(){return this.lastContent}};function k(t,e,o){let r=new R({cookieFile:t,onCookieChange:e,onError:o});return r.start(),r}function S(t){return["production","prod","prd","release","staging","uat"].includes(t.toLowerCase().trim())}function _(t=[],e=!1,o="[env-detector]"){let r=process.env;if(t.length>0)for(let s of t){let a=r[s];if(a&&S(a))return e&&console.log(`${o} Detected production via custom env: ${s}=${a}`),!0}let n=["NODE_ENV","BUILD_MODE","VUE_APP_ENV","VITE_NODE_ENV","WEBPACK_MODE","CI_ENV","APP_ENV","ENV","DEPLOY_ENV","RUN_MODE"];for(let s of n){let a=r[s];if(a&&S(a))return e&&console.log(`${o} Detected production via env: ${s}=${a}`),!0}if(r.CI==="true"||r.CI==="1"||r.CI==="yes")return e&&console.log(`${o} Detected production via CI env`),!0;if(r.npm_lifecycle_event){let s=r.npm_lifecycle_event.toLowerCase();if(s.includes("build")||s.includes("prod")||s.includes("prd")||s.includes("release"))return e&&console.log(`${o} Detected production via lifecycle event: ${r.npm_lifecycle_event}`),!0}let i=process.argv.join("").toLowerCase();return i.includes("build")||i.includes("production")||i.includes("--mode=production")||i.includes("--prod")||i.includes("--release")?(e&&console.log(`${o} Detected production via process arguments`),!0):!1}function x(t,e=[],o=!1,r="[env-detector]"){return typeof t=="boolean"?(o&&!t&&console.log(`${r} Watch disabled by user setting`),t):_(e,o,r)?(o&&console.log(`${r} Auto-detected production mode - disabling watch`),!1):(o&&console.log(`${r} Auto-detected development mode - enabling watch`),!0)}function C(t,e){e&&(t.removeHeader("cookie"),t.removeHeader("Cookie"),t.setHeader("Cookie",e))}var m=class{constructor(e){this.currentCookie="";this.server=null;this.proxyServer=null;this.watcher=null;this.handleCookieChange=e=>{if(e!==this.currentCookie&&(this.currentCookie=e,this.log("info","[AutoProxyCookie] Cookie updated:",e?"(has cookie)":"(empty)"),this.options.autoRestart&&this.options.restartMarkerFile)){let o=q.resolve(this.options.restartMarkerFile);L.writeFileSync(o,JSON.stringify({timestamp:Date.now(),cookie:e},null,2)),this.log("info","[AutoProxyCookie] Restart marker written to:",o),this.log("info","[AutoProxyCookie] Please restart the dev server for changes to take effect")}};this.handleOnProxyReq=(e,o,r,n)=>{if(this.currentCookie&&C(e,this.currentCookie),this.log("debug","[AutoProxyCookie] Proxy Request:",o.method,o.url),this.options.hooks.onProxyReq)try{this.options.hooks.onProxyReq(e,o,r)}catch(i){this.log("error","[AutoProxyCookie] onProxyReq hook error:",i.message)}};this.handleOnProxyRes=(e,o,r)=>{let n=["Content-Type","Content-Length","Authorization","Set-Cookie","X-Requested-With","Access-Control-Allow-Origin","Access-Control-Allow-Credentials"];if(r.setHeader("Access-Control-Allow-Origin","*"),r.setHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE, OPTIONS"),r.setHeader("Access-Control-Allow-Headers",n.join(",")),r.setHeader("Access-Control-Allow-Credentials","true"),this.log("debug","[AutoProxyCookie] Proxy Response:",o.url,e.statusCode),this.options.hooks.onProxyRes)try{this.options.hooks.onProxyRes(e,o,r)}catch(i){this.log("error","[AutoProxyCookie] onProxyRes hook error:",i.message)}};this.handleOnError=(e,o,r)=>{if(this.log("error","[AutoProxyCookie] Proxy Error:",e.message),this.log("error","[AutoProxyCookie] URL:",o.url),r instanceof H.ServerResponse&&!r.headersSent&&(r.writeHead(503,{"Content-Type":"application/json; charset=utf-8"}),r.end(JSON.stringify({success:!1,message:"\u670D\u52A1\u6682\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",error:e.message}))),this.options.hooks.onError)try{this.options.hooks.onError(e,o,r)}catch(n){this.log("error","[AutoProxyCookie] onError hook error:",n.message)}};this.handleOnWsError=(e,o,r)=>{if(this.log("error","[AutoProxyCookie] WebSocket Proxy Error:",e.message),this.log("error","[AutoProxyCookie] WebSocket URL:",o.url),r&&r.close(),this.options.hooks.onWsError)try{this.options.hooks.onWsError(e,o,r)}catch(n){this.log("error","[AutoProxyCookie] onWsError hook error:",n.message)}};let r={...e,hooks:{...{onProxyReq:()=>{},onProxyRes:()=>{},onError:()=>{},onWsError:()=>{}},...e.hooks||{}}};this.options={debug:!1,autoRestart:!1,restartMarkerFile:".cookie-restart-marker",proxyMap:{},ignorePaths:[],ws:!0,changeOrigin:!0,secure:!1,followRedirects:!0,autoRewrite:!1,protocolRewrite:void 0,logLevel:"info",cookieDomainRewrite:"*",cookiePathRewrite:!1,headers:{},...r},this.cookieReader=new u({cookieFile:e.cookieFile})}getProxyUrl(e){let o=e.url?.split("?")[0]||"/",r=this.options.proxyMap||{};for(let[n,i]of Object.entries(r))if(o.startsWith(n))return i;return this.options.target}isIgnoredPath(e){return(this.options.ignorePaths||[]).some(r=>e.startsWith(r))}log(e,...o){let r={debug:0,info:1,warn:2,error:3},n=r[this.options.logLevel||"info"];r[e]>=n&&(e==="error"?console.error(...o):e==="warn"?console.warn(...o):console.log(...o))}createProxyOptions(e){let{ws:o,changeOrigin:r,secure:n,followRedirects:i,autoRewrite:s,protocolRewrite:a,cookieDomainRewrite:c,cookiePathRewrite:p,headers:h}=this.options;return{target:e,ws:o,changeOrigin:r,secure:n,followRedirects:i,autoRewrite:s,protocolRewrite:a,cookieDomainRewrite:c,cookiePathRewrite:p,headers:{...h},ignorePath:!1}}async setup(e){this.server=e,this.currentCookie=this.cookieReader.readCookie();try{let o={target:this.options.target,changeOrigin:this.options.changeOrigin,secure:this.options.secure,followRedirects:this.options.followRedirects,autoRewrite:this.options.autoRewrite,protocolRewrite:this.options.protocolRewrite,cookieDomainRewrite:this.options.cookieDomainRewrite,cookiePathRewrite:this.options.cookiePathRewrite,ws:this.options.ws};this.proxyServer=N.default.createProxyServer(o),this.proxyServer.on("proxyReq",this.handleOnProxyReq),this.proxyServer.on("proxyRes",this.handleOnProxyRes),this.proxyServer.on("error",this.handleOnError),this.options.ws&&this.proxyServer.on("wsError",this.handleOnWsError),this.log("info","[AutoProxyCookie] Proxy server created with WebSocket support")}catch(o){this.log("warn","[AutoProxyCookie] http-proxy create failed, using basic mode:",o.message)}e.middlewares.use((o,r,n)=>{let i=new URL(o.url||"/","http://localhost").pathname;if(this.isIgnoredPath(i)){n();return}if(this.currentCookie=this.cookieReader.readCookie(),this.proxyServer){let s=this.getProxyUrl(o);(this.options.debug||this.options.logLevel==="debug")&&this.log("info",`[AutoProxyCookie] ${i} -> ${s}`);let a=this.createProxyOptions(s);try{this.proxyServer.web(o,r,a)}catch(c){this.log("error","[AutoProxyCookie] Proxy web error:",c.message),n(c)}}else n()}),this.options.ws&&this.server.httpServer&&this.proxyServer&&(this.server.httpServer.on("upgrade",(o,r,n)=>{let i=new URL(o.url||"/","http://localhost").pathname;if(this.isIgnoredPath(i)){r.destroy();return}let s=this.getProxyUrl(o);this.proxyServer?.ws(o,r,n,{target:s,ws:!0,changeOrigin:this.options.changeOrigin,secure:this.options.secure})}),this.log("info","[AutoProxyCookie] WebSocket upgrade handler registered")),this.startFileWatch(),this.log("info","[AutoProxyCookie] Auto-proxy middleware enabled"),this.log("info","[AutoProxyCookie] Target:",this.options.target),this.log("info","[AutoProxyCookie] Cookie file:",this.options.cookieFile),this.options.autoRestart&&this.log("info","[AutoProxyCookie] Auto-restart enabled"),this.options.ws&&this.log("info","[AutoProxyCookie] WebSocket support enabled")}startFileWatch(){let e;this.options.isDev!==void 0?(e=this.options.isDev,this.options.debug&&console.log(`[AutoProxyCookie] isDev=${this.options.isDev}, ${e?"enabling":"disabling"} watch`)):(e=!0,this.options.debug&&console.log("[AutoProxyCookie] Default behavior: enabling watch (dev mode)")),e?this.watcher=k(this.options.cookieFile,this.handleCookieChange,o=>{this.log("error","[AutoProxyCookie] File watch error:",o.message)}):this.options.debug&&console.log("[AutoProxyCookie] File watch disabled")}stop(){this.watcher&&(this.watcher.stop(),this.watcher=null),this.proxyServer&&(this.proxyServer.close(),this.proxyServer=null),this.log("info","[AutoProxyCookie] Stopped")}getCurrentCookie(){return this.currentCookie}};function O(t){return new m(t)}function E(t){let{name:e="vite-auto-proxy-cookie",isDev:o,...r}=t,n=null;return{name:e,apply:"serve",async configureServer(i){n=O({...r,debug:t.debug??!1,autoRestart:t.autoRestart??!0,isDev:o});try{await n.setup(i)}catch(s){console.error("[vite-auto-proxy-cookie] Failed to setup proxy:",s),t.debug&&console.log("[vite-auto-proxy-cookie] Falling back to middleware mode")}},closeBundle(){n?.stop()}}}function A(t){let{cookieFile:e,debug:o=!1,onCookieChange:r,watch:n="auto",isDev:i}=t,s=null,a="",c=new u({cookieFile:e});return{name:"vite-dev-proxy-cookie",apply:"serve",configureServer(p){a=c.readCookie(),o&&console.log("[vite-dev-proxy-cookie] Initial cookie loaded");let h=p.middlewares||p._middlewares||p.app;h&&typeof h.use=="function"?h.use((l,y,b)=>{a&&l.url?.startsWith("/")&&(l.headers=l.headers||{},l.headers.cookie=a),b()}):console.warn("[vite-dev-proxy-cookie] Could not access middleware stack, cookie injection disabled");let g;i!==void 0?(g=i,o&&console.log(`[vite-dev-proxy-cookie] isDev=${i}, ${g?"enabling":"disabling"} watch`)):g=x(n,[],o,"[vite-dev-proxy-cookie]"),g?s=k(e,l=>{a=l,r?.(l),console.log("[vite-dev-proxy-cookie] Cookie changed, please restart server for full effect")},l=>{console.error("[vite-dev-proxy-cookie] Watch error:",l.message)}):o&&console.log("[vite-dev-proxy-cookie] File watch disabled")},closeBundle(){s?.stop()}}}var F=f(require("path"));function D(t,e={}){let{getCookie:o,debug:r=!1,headers:n={},ws:i=!1,changeOrigin:s=!0,secure:a=!1,onError:c}=e;return{ws:i,target:t,changeOrigin:s,secure:a,headers:n,onProxyReq:(h,g)=>{let l=o?o():"";if(l&&C(h,l),r){let y=g.url||"/";console.log("[Proxy Request]",y,g.method,l?"(with cookie)":"(no cookie)")}},onError:c||(h=>{console.error(`
3
+ [Proxy Error]`,h.message)})}}function X(t,e={}){let{watch:o="auto",debug:r=!1,productionEnvs:n=[],isDev:i}=e,s=new u({cookieFile:F.resolve(t)}),a;return i!==void 0?(a=i,r&&console.log(`[CookieFile] isDev=${i}, ${a?"enabling":"disabling"} watch`)):a=x(o,n,r,"[CookieFile]"),a?k(F.resolve(t),c=>{r&&console.log("[CookieFile] Updated:",c?"(has cookie)":"(empty)")},c=>{console.error("[CookieFile] Watch error:",c.message)}):r&&console.log("[CookieFile] File watch disabled"),()=>s.readCookie()}function Y(t){let{target:e,ignorePaths:o=[],includePaths:r=[],additionalProxies:n={},getCookie:i,debug:s,headers:a}=t,c={};if(r.length>0)for(let p of r)c[p]=D(e,{getCookie:i,debug:s,headers:a});else{let p={ws:!1,target:e,changeOrigin:!0,secure:!1,headers:a,onProxyReq:(h,g)=>{let l=g.url||"/";if(o.some(b=>l.startsWith(b)))return;let y=i?i():"";y&&C(h,y),s&&console.log("[Proxy Request]",l,g.method,y?"(with cookie)":"(no cookie)")},onError:h=>{console.error(`
4
+ [Proxy Error]`,h.message)}};c["/"]=p}for(let[p,h]of Object.entries(n))c[p]=D(h,{getCookie:i,debug:s,headers:a});return c}var M="",P=null;function V(){if(P!==null)return P;try{M=require("vite/package.json").version,P=parseInt(M.split(".")[0],10)}catch{P=5}return P}function Q(t){let{mode:e="auto",watch:o="auto",isDev:r,...n}=t,i=V();if(t.debug&&console.log(`[dev-proxy-cookie] Detected Vite ${i}.x`),e==="cookie"||e==="auto"&&!t.target)return A({cookieFile:t.cookieFile,debug:t.debug,onCookieChange:t.onCookieChange,watch:o,isDev:r});let s={cookieFile:t.cookieFile,target:t.target,debug:t.debug,autoRestart:t.autoRestart??!0,restartMarkerFile:t.restartMarkerFile,proxyMap:t.proxyMap,ignorePaths:t.ignorePaths};return E(s)}function Z(){return V(),M}function ee(){return V()}0&&(module.exports={AutoProxyCookie,CookieReader,CookieWatcher,createAutoProxyConfig,createAutoProxyCookie,createCookieGetter,createDevProxyCookie,createFileCookieGetter,createVueProxyConfig,detectProductionEnvironment,getViteMajorVersion,getViteVersion,isProductionValue,shouldEnableWatch,viteAutoProxyCookie,viteDevProxyCookie,watchCookieFile});
@@ -1,4 +1,4 @@
1
- var D=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,o)=>(typeof require<"u"?require:e)[o]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});import*as b from"http";import*as O from"fs";import*as A from"path";import H from"http-proxy";import*as p from"fs";import*as y from"path";var g=class{constructor(e){this.options={encoding:"utf-8",...e}}readCookie(){try{let e=y.resolve(this.options.cookieFile);return p.existsSync(e)?p.readFileSync(e,this.options.encoding||"utf-8").split(`
2
- `).map(i=>i.trim()).filter(i=>i&&!i.startsWith("#")).join("; "):""}catch{return""}}ensureCookieFile(){let e=y.resolve(this.options.cookieFile),o=y.dirname(e);p.existsSync(o)||p.mkdirSync(o,{recursive:!0}),p.existsSync(e)||p.writeFileSync(e,"")}};function L(t){let e=new g({cookieFile:t});return()=>e.readCookie()}import*as S from"path";import V from"chokidar";var P=class{constructor(e){this.watcher=null;this.lastContent="";this.handleChange=()=>{let e=this.cookieReader.readCookie();e!==this.lastContent&&(this.lastContent=e,this.options.onCookieChange(e),console.log(`[CookieWatcher] Cookie updated from file: ${this.options.cookieFile}`))};this.options={autoCreateFile:!0,...e},this.cookieReader=new g({cookieFile:e.cookieFile})}start(){this.options.autoCreateFile&&this.cookieReader.ensureCookieFile();let e=S.resolve(this.options.cookieFile);this.lastContent=this.cookieReader.readCookie(),console.log(`[CookieWatcher] Started watching: ${e}`);try{this.watcher=V.watch(e,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}}),this.watcher.on("change",this.handleChange),this.watcher.on("add",this.handleChange),this.watcher.on("error",o=>{this.options.onError?.(o)})}catch(o){this.options.onError?.(o)}}stop(){this.watcher&&(this.watcher.close(),this.watcher=null,console.log(`[CookieWatcher] Stopped watching: ${this.options.cookieFile}`))}getCurrentCookie(){return this.lastContent}};function k(t,e,o){let r=new P({cookieFile:t,onCookieChange:e,onError:o});return r.start(),r}function x(t,e){e&&(t.removeHeader("cookie"),t.removeHeader("Cookie"),t.setHeader("Cookie",e))}var C=class{constructor(e){this.currentCookie="";this.server=null;this.proxyServer=null;this.watcher=null;this.handleCookieChange=e=>{if(e!==this.currentCookie&&(this.currentCookie=e,this.log("info","[AutoProxyCookie] Cookie updated:",e?"(has cookie)":"(empty)"),this.options.autoRestart&&this.options.restartMarkerFile)){let o=A.resolve(this.options.restartMarkerFile);O.writeFileSync(o,JSON.stringify({timestamp:Date.now(),cookie:e},null,2)),this.log("info","[AutoProxyCookie] Restart marker written to:",o),this.log("info","[AutoProxyCookie] Please restart the dev server for changes to take effect")}};this.handleOnProxyReq=(e,o,r,s)=>{if(this.currentCookie&&x(e,this.currentCookie),this.log("debug","[AutoProxyCookie] Proxy Request:",o.method,o.url),this.options.hooks.onProxyReq)try{this.options.hooks.onProxyReq(e,o,r)}catch(i){this.log("error","[AutoProxyCookie] onProxyReq hook error:",i.message)}};this.handleOnProxyRes=(e,o,r)=>{let s=["Content-Type","Content-Length","Authorization","Set-Cookie","X-Requested-With","Access-Control-Allow-Origin","Access-Control-Allow-Credentials"];if(r.setHeader("Access-Control-Allow-Origin","*"),r.setHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE, OPTIONS"),r.setHeader("Access-Control-Allow-Headers",s.join(",")),r.setHeader("Access-Control-Allow-Credentials","true"),this.log("debug","[AutoProxyCookie] Proxy Response:",o.url,e.statusCode),this.options.hooks.onProxyRes)try{this.options.hooks.onProxyRes(e,o,r)}catch(i){this.log("error","[AutoProxyCookie] onProxyRes hook error:",i.message)}};this.handleOnError=(e,o,r)=>{if(this.log("error","[AutoProxyCookie] Proxy Error:",e.message),this.log("error","[AutoProxyCookie] URL:",o.url),r instanceof b.ServerResponse&&!r.headersSent&&(r.writeHead(503,{"Content-Type":"application/json; charset=utf-8"}),r.end(JSON.stringify({success:!1,message:"\u670D\u52A1\u6682\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",error:e.message}))),this.options.hooks.onError)try{this.options.hooks.onError(e,o,r)}catch(s){this.log("error","[AutoProxyCookie] onError hook error:",s.message)}};this.handleOnWsError=(e,o,r)=>{if(this.log("error","[AutoProxyCookie] WebSocket Proxy Error:",e.message),this.log("error","[AutoProxyCookie] WebSocket URL:",o.url),r&&r.close(),this.options.hooks.onWsError)try{this.options.hooks.onWsError(e,o,r)}catch(s){this.log("error","[AutoProxyCookie] onWsError hook error:",s.message)}};let r={...e,hooks:{...{onProxyReq:()=>{},onProxyRes:()=>{},onError:()=>{},onWsError:()=>{}},...e.hooks||{}}};this.options={debug:!1,autoRestart:!1,restartMarkerFile:".cookie-restart-marker",proxyMap:{},ignorePaths:[],ws:!0,changeOrigin:!0,secure:!1,followRedirects:!0,autoRewrite:!1,protocolRewrite:void 0,logLevel:"info",cookieDomainRewrite:"*",cookiePathRewrite:!1,headers:{},...r},this.cookieReader=new g({cookieFile:e.cookieFile})}getProxyUrl(e){let o=e.url?.split("?")[0]||"/",r=this.options.proxyMap||{};for(let[s,i]of Object.entries(r))if(o.startsWith(s))return i;return this.options.target}isIgnoredPath(e){return(this.options.ignorePaths||[]).some(r=>e.startsWith(r))}log(e,...o){let r={debug:0,info:1,warn:2,error:3},s=r[this.options.logLevel||"info"];r[e]>=s&&(e==="error"?console.error(...o):e==="warn"?console.warn(...o):console.log(...o))}createProxyOptions(e){let{ws:o,changeOrigin:r,secure:s,followRedirects:i,autoRewrite:c,protocolRewrite:l,cookieDomainRewrite:a,cookiePathRewrite:n,headers:h}=this.options;return{target:e,ws:o,changeOrigin:r,secure:s,followRedirects:i,autoRewrite:c,protocolRewrite:l,cookieDomainRewrite:a,cookiePathRewrite:n,headers:{...h},ignorePath:!1}}async setup(e){this.server=e,this.currentCookie=this.cookieReader.readCookie();try{let o={target:this.options.target,changeOrigin:this.options.changeOrigin,secure:this.options.secure,followRedirects:this.options.followRedirects,autoRewrite:this.options.autoRewrite,protocolRewrite:this.options.protocolRewrite,cookieDomainRewrite:this.options.cookieDomainRewrite,cookiePathRewrite:this.options.cookiePathRewrite,ws:this.options.ws};this.proxyServer=H.createProxyServer(o),this.proxyServer.on("proxyReq",this.handleOnProxyReq),this.proxyServer.on("proxyRes",this.handleOnProxyRes),this.proxyServer.on("error",this.handleOnError),this.options.ws&&this.proxyServer.on("wsError",this.handleOnWsError),this.log("info","[AutoProxyCookie] Proxy server created with WebSocket support")}catch(o){this.log("warn","[AutoProxyCookie] http-proxy create failed, using basic mode:",o.message)}e.middlewares.use((o,r,s)=>{let i=new URL(o.url||"/","http://localhost").pathname;if(this.isIgnoredPath(i)){s();return}if(this.currentCookie=this.cookieReader.readCookie(),this.proxyServer){let c=this.getProxyUrl(o);(this.options.debug||this.options.logLevel==="debug")&&this.log("info",`[AutoProxyCookie] ${i} -> ${c}`);let l=this.createProxyOptions(c);try{this.proxyServer.web(o,r,l)}catch(a){this.log("error","[AutoProxyCookie] Proxy web error:",a.message),s(a)}}else s()}),this.options.ws&&this.server.httpServer&&this.proxyServer&&(this.server.httpServer.on("upgrade",(o,r,s)=>{let i=new URL(o.url||"/","http://localhost").pathname;if(this.isIgnoredPath(i)){r.destroy();return}let c=this.getProxyUrl(o);this.proxyServer?.ws(o,r,s,{target:c,ws:!0,changeOrigin:this.options.changeOrigin,secure:this.options.secure})}),this.log("info","[AutoProxyCookie] WebSocket upgrade handler registered")),this.startFileWatch(),this.log("info","[AutoProxyCookie] Auto-proxy middleware enabled"),this.log("info","[AutoProxyCookie] Target:",this.options.target),this.log("info","[AutoProxyCookie] Cookie file:",this.options.cookieFile),this.options.autoRestart&&this.log("info","[AutoProxyCookie] Auto-restart enabled"),this.options.ws&&this.log("info","[AutoProxyCookie] WebSocket support enabled")}startFileWatch(){this.watcher=k(this.options.cookieFile,this.handleCookieChange,e=>{this.log("error","[AutoProxyCookie] File watch error:",e.message)})}stop(){this.watcher&&(this.watcher.stop(),this.watcher=null),this.proxyServer&&(this.proxyServer.close(),this.proxyServer=null),this.log("info","[AutoProxyCookie] Stopped")}getCurrentCookie(){return this.currentCookie}};function E(t){return new C(t)}function F(t){let{name:e="vite-auto-proxy-cookie",...o}=t,r=null;return{name:e,apply:"serve",async configureServer(s){r=E({...o,debug:t.debug??!1,autoRestart:t.autoRestart??!0});try{await r.setup(s)}catch(i){console.error("[vite-auto-proxy-cookie] Failed to setup proxy:",i),t.debug&&console.log("[vite-auto-proxy-cookie] Falling back to middleware mode")}},closeBundle(){r?.stop()}}}function M(t){let{cookieFile:e,debug:o=!1,onCookieChange:r}=t,s=null,i="",c=new g({cookieFile:e});return{name:"vite-dev-proxy-cookie",apply:"serve",configureServer(l){i=c.readCookie(),o&&console.log("[vite-dev-proxy-cookie] Initial cookie loaded");let a=l.middlewares||l._middlewares||l.app;a&&typeof a.use=="function"?a.use((n,h,u)=>{i&&n.url?.startsWith("/")&&(n.headers=n.headers||{},n.headers.cookie=i),u()}):console.warn("[vite-dev-proxy-cookie] Could not access middleware stack, cookie injection disabled"),s=k(e,n=>{i=n,r?.(n),console.log("[vite-dev-proxy-cookie] Cookie changed, please restart server for full effect")},n=>{console.error("[vite-dev-proxy-cookie] Watch error:",n.message)})},closeBundle(){s?.stop()}}}import*as m from"path";function W(t,e={}){let{getCookie:o,debug:r=!1,headers:s={},ws:i=!1,changeOrigin:c=!0,secure:l=!1,onError:a}=e;return{ws:i,target:t,changeOrigin:c,secure:l,headers:s,onProxyReq:(h,u)=>{let d=o?o():"";if(d&&x(h,d),r){let f=u.url||"/";console.log("[Proxy Request]",f,u.method,d?"(with cookie)":"(no cookie)")}},onError:a||(h=>{console.error(`
3
- [Proxy Error]`,h.message)})}}function ne(t,e={}){let{watch:o=!0,debug:r=!1}=e,s=new g({cookieFile:m.resolve(t)});return o&&k(m.resolve(t),i=>{r&&console.log("[CookieFile] Updated:",i?"(has cookie)":"(empty)")},i=>{console.error("[CookieFile] Watch error:",i.message)}),()=>s.readCookie()}function ae(t){let{target:e,ignorePaths:o=[],includePaths:r=[],additionalProxies:s={},getCookie:i,debug:c,headers:l}=t,a={};if(r.length>0)for(let n of r)a[n]=W(e,{getCookie:i,debug:c,headers:l});else{let n={ws:!1,target:e,changeOrigin:!0,secure:!1,headers:l,onProxyReq:(h,u)=>{let d=u.url||"/";if(o.some(I=>d.startsWith(I)))return;let f=i?i():"";f&&x(h,f),c&&console.log("[Proxy Request]",d,u.method,f?"(with cookie)":"(no cookie)")},onError:h=>{console.error(`
4
- [Proxy Error]`,h.message)}};a["/"]=n}for(let[n,h]of Object.entries(s))a[n]=W(h,{getCookie:i,debug:c,headers:l});return a}var w="",v=null;function R(){if(v!==null)return v;try{w=D("vite/package.json").version,v=parseInt(w.split(".")[0],10)}catch{v=5}return v}function ge(t){let{mode:e="auto",...o}=t,r=R();if(t.debug&&console.log(`[dev-proxy-cookie] Detected Vite ${r}.x`),e==="cookie"||e==="auto"&&!t.target)return M({cookieFile:t.cookieFile,debug:t.debug,onCookieChange:t.onCookieChange});let s={cookieFile:t.cookieFile,target:t.target,debug:t.debug,autoRestart:t.autoRestart??!0,restartMarkerFile:t.restartMarkerFile,proxyMap:t.proxyMap,ignorePaths:t.ignorePaths};return F(s)}function pe(){return R(),w}function ue(){return R()}export{C as AutoProxyCookie,g as CookieReader,P as CookieWatcher,ae as createAutoProxyConfig,E as createAutoProxyCookie,L as createCookieGetter,ge as createDevProxyCookie,ne as createFileCookieGetter,W as createVueProxyConfig,ue as getViteMajorVersion,pe as getViteVersion,F as viteAutoProxyCookie,M as viteDevProxyCookie,k as watchCookieFile};
1
+ var $=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,o)=>(typeof require<"u"?require:e)[o]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});import*as A from"http";import*as F from"fs";import*as D from"path";import L from"http-proxy";import*as d from"fs";import*as y from"path";var u=class{constructor(e){this.options={encoding:"utf-8",...e}}readCookie(){try{let e=y.resolve(this.options.cookieFile);return d.existsSync(e)?d.readFileSync(e,this.options.encoding||"utf-8").split(`
2
+ `).map(i=>i.trim()).filter(i=>i&&!i.startsWith("#")).join("; "):""}catch{return""}}ensureCookieFile(){let e=y.resolve(this.options.cookieFile),o=y.dirname(e);d.existsSync(o)||d.mkdirSync(o,{recursive:!0}),d.existsSync(e)||d.writeFileSync(e,"")}};function N(t){let e=new u({cookieFile:t});return()=>e.readCookie()}import*as O from"path";import _ from"chokidar";var w=class{constructor(e){this.watcher=null;this.lastContent="";this.handleChange=()=>{let e=this.cookieReader.readCookie();e!==this.lastContent&&(this.lastContent=e,this.options.onCookieChange(e),console.log(`[CookieWatcher] Cookie updated from file: ${this.options.cookieFile}`))};this.options={autoCreateFile:!0,...e},this.cookieReader=new u({cookieFile:e.cookieFile})}start(){this.options.autoCreateFile&&this.cookieReader.ensureCookieFile();let e=O.resolve(this.options.cookieFile);this.lastContent=this.cookieReader.readCookie(),console.log(`[CookieWatcher] Started watching: ${e}`);try{this.watcher=_.watch(e,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}}),this.watcher.on("change",this.handleChange),this.watcher.on("add",this.handleChange),this.watcher.on("error",o=>{this.options.onError?.(o)})}catch(o){this.options.onError?.(o)}}stop(){this.watcher&&(this.watcher.close(),this.watcher=null,console.log(`[CookieWatcher] Stopped watching: ${this.options.cookieFile}`))}getCurrentCookie(){return this.lastContent}};function k(t,e,o){let r=new w({cookieFile:t,onCookieChange:e,onError:o});return r.start(),r}function E(t){return["production","prod","prd","release","staging","uat"].includes(t.toLowerCase().trim())}function H(t=[],e=!1,o="[env-detector]"){let r=process.env;if(t.length>0)for(let s of t){let a=r[s];if(a&&E(a))return e&&console.log(`${o} Detected production via custom env: ${s}=${a}`),!0}let n=["NODE_ENV","BUILD_MODE","VUE_APP_ENV","VITE_NODE_ENV","WEBPACK_MODE","CI_ENV","APP_ENV","ENV","DEPLOY_ENV","RUN_MODE"];for(let s of n){let a=r[s];if(a&&E(a))return e&&console.log(`${o} Detected production via env: ${s}=${a}`),!0}if(r.CI==="true"||r.CI==="1"||r.CI==="yes")return e&&console.log(`${o} Detected production via CI env`),!0;if(r.npm_lifecycle_event){let s=r.npm_lifecycle_event.toLowerCase();if(s.includes("build")||s.includes("prod")||s.includes("prd")||s.includes("release"))return e&&console.log(`${o} Detected production via lifecycle event: ${r.npm_lifecycle_event}`),!0}let i=process.argv.join("").toLowerCase();return i.includes("build")||i.includes("production")||i.includes("--mode=production")||i.includes("--prod")||i.includes("--release")?(e&&console.log(`${o} Detected production via process arguments`),!0):!1}function C(t,e=[],o=!1,r="[env-detector]"){return typeof t=="boolean"?(o&&!t&&console.log(`${r} Watch disabled by user setting`),t):H(e,o,r)?(o&&console.log(`${r} Auto-detected production mode - disabling watch`),!1):(o&&console.log(`${r} Auto-detected development mode - enabling watch`),!0)}function v(t,e){e&&(t.removeHeader("cookie"),t.removeHeader("Cookie"),t.setHeader("Cookie",e))}var m=class{constructor(e){this.currentCookie="";this.server=null;this.proxyServer=null;this.watcher=null;this.handleCookieChange=e=>{if(e!==this.currentCookie&&(this.currentCookie=e,this.log("info","[AutoProxyCookie] Cookie updated:",e?"(has cookie)":"(empty)"),this.options.autoRestart&&this.options.restartMarkerFile)){let o=D.resolve(this.options.restartMarkerFile);F.writeFileSync(o,JSON.stringify({timestamp:Date.now(),cookie:e},null,2)),this.log("info","[AutoProxyCookie] Restart marker written to:",o),this.log("info","[AutoProxyCookie] Please restart the dev server for changes to take effect")}};this.handleOnProxyReq=(e,o,r,n)=>{if(this.currentCookie&&v(e,this.currentCookie),this.log("debug","[AutoProxyCookie] Proxy Request:",o.method,o.url),this.options.hooks.onProxyReq)try{this.options.hooks.onProxyReq(e,o,r)}catch(i){this.log("error","[AutoProxyCookie] onProxyReq hook error:",i.message)}};this.handleOnProxyRes=(e,o,r)=>{let n=["Content-Type","Content-Length","Authorization","Set-Cookie","X-Requested-With","Access-Control-Allow-Origin","Access-Control-Allow-Credentials"];if(r.setHeader("Access-Control-Allow-Origin","*"),r.setHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE, OPTIONS"),r.setHeader("Access-Control-Allow-Headers",n.join(",")),r.setHeader("Access-Control-Allow-Credentials","true"),this.log("debug","[AutoProxyCookie] Proxy Response:",o.url,e.statusCode),this.options.hooks.onProxyRes)try{this.options.hooks.onProxyRes(e,o,r)}catch(i){this.log("error","[AutoProxyCookie] onProxyRes hook error:",i.message)}};this.handleOnError=(e,o,r)=>{if(this.log("error","[AutoProxyCookie] Proxy Error:",e.message),this.log("error","[AutoProxyCookie] URL:",o.url),r instanceof A.ServerResponse&&!r.headersSent&&(r.writeHead(503,{"Content-Type":"application/json; charset=utf-8"}),r.end(JSON.stringify({success:!1,message:"\u670D\u52A1\u6682\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",error:e.message}))),this.options.hooks.onError)try{this.options.hooks.onError(e,o,r)}catch(n){this.log("error","[AutoProxyCookie] onError hook error:",n.message)}};this.handleOnWsError=(e,o,r)=>{if(this.log("error","[AutoProxyCookie] WebSocket Proxy Error:",e.message),this.log("error","[AutoProxyCookie] WebSocket URL:",o.url),r&&r.close(),this.options.hooks.onWsError)try{this.options.hooks.onWsError(e,o,r)}catch(n){this.log("error","[AutoProxyCookie] onWsError hook error:",n.message)}};let r={...e,hooks:{...{onProxyReq:()=>{},onProxyRes:()=>{},onError:()=>{},onWsError:()=>{}},...e.hooks||{}}};this.options={debug:!1,autoRestart:!1,restartMarkerFile:".cookie-restart-marker",proxyMap:{},ignorePaths:[],ws:!0,changeOrigin:!0,secure:!1,followRedirects:!0,autoRewrite:!1,protocolRewrite:void 0,logLevel:"info",cookieDomainRewrite:"*",cookiePathRewrite:!1,headers:{},...r},this.cookieReader=new u({cookieFile:e.cookieFile})}getProxyUrl(e){let o=e.url?.split("?")[0]||"/",r=this.options.proxyMap||{};for(let[n,i]of Object.entries(r))if(o.startsWith(n))return i;return this.options.target}isIgnoredPath(e){return(this.options.ignorePaths||[]).some(r=>e.startsWith(r))}log(e,...o){let r={debug:0,info:1,warn:2,error:3},n=r[this.options.logLevel||"info"];r[e]>=n&&(e==="error"?console.error(...o):e==="warn"?console.warn(...o):console.log(...o))}createProxyOptions(e){let{ws:o,changeOrigin:r,secure:n,followRedirects:i,autoRewrite:s,protocolRewrite:a,cookieDomainRewrite:c,cookiePathRewrite:p,headers:h}=this.options;return{target:e,ws:o,changeOrigin:r,secure:n,followRedirects:i,autoRewrite:s,protocolRewrite:a,cookieDomainRewrite:c,cookiePathRewrite:p,headers:{...h},ignorePath:!1}}async setup(e){this.server=e,this.currentCookie=this.cookieReader.readCookie();try{let o={target:this.options.target,changeOrigin:this.options.changeOrigin,secure:this.options.secure,followRedirects:this.options.followRedirects,autoRewrite:this.options.autoRewrite,protocolRewrite:this.options.protocolRewrite,cookieDomainRewrite:this.options.cookieDomainRewrite,cookiePathRewrite:this.options.cookiePathRewrite,ws:this.options.ws};this.proxyServer=L.createProxyServer(o),this.proxyServer.on("proxyReq",this.handleOnProxyReq),this.proxyServer.on("proxyRes",this.handleOnProxyRes),this.proxyServer.on("error",this.handleOnError),this.options.ws&&this.proxyServer.on("wsError",this.handleOnWsError),this.log("info","[AutoProxyCookie] Proxy server created with WebSocket support")}catch(o){this.log("warn","[AutoProxyCookie] http-proxy create failed, using basic mode:",o.message)}e.middlewares.use((o,r,n)=>{let i=new URL(o.url||"/","http://localhost").pathname;if(this.isIgnoredPath(i)){n();return}if(this.currentCookie=this.cookieReader.readCookie(),this.proxyServer){let s=this.getProxyUrl(o);(this.options.debug||this.options.logLevel==="debug")&&this.log("info",`[AutoProxyCookie] ${i} -> ${s}`);let a=this.createProxyOptions(s);try{this.proxyServer.web(o,r,a)}catch(c){this.log("error","[AutoProxyCookie] Proxy web error:",c.message),n(c)}}else n()}),this.options.ws&&this.server.httpServer&&this.proxyServer&&(this.server.httpServer.on("upgrade",(o,r,n)=>{let i=new URL(o.url||"/","http://localhost").pathname;if(this.isIgnoredPath(i)){r.destroy();return}let s=this.getProxyUrl(o);this.proxyServer?.ws(o,r,n,{target:s,ws:!0,changeOrigin:this.options.changeOrigin,secure:this.options.secure})}),this.log("info","[AutoProxyCookie] WebSocket upgrade handler registered")),this.startFileWatch(),this.log("info","[AutoProxyCookie] Auto-proxy middleware enabled"),this.log("info","[AutoProxyCookie] Target:",this.options.target),this.log("info","[AutoProxyCookie] Cookie file:",this.options.cookieFile),this.options.autoRestart&&this.log("info","[AutoProxyCookie] Auto-restart enabled"),this.options.ws&&this.log("info","[AutoProxyCookie] WebSocket support enabled")}startFileWatch(){let e;this.options.isDev!==void 0?(e=this.options.isDev,this.options.debug&&console.log(`[AutoProxyCookie] isDev=${this.options.isDev}, ${e?"enabling":"disabling"} watch`)):(e=!0,this.options.debug&&console.log("[AutoProxyCookie] Default behavior: enabling watch (dev mode)")),e?this.watcher=k(this.options.cookieFile,this.handleCookieChange,o=>{this.log("error","[AutoProxyCookie] File watch error:",o.message)}):this.options.debug&&console.log("[AutoProxyCookie] File watch disabled")}stop(){this.watcher&&(this.watcher.stop(),this.watcher=null),this.proxyServer&&(this.proxyServer.close(),this.proxyServer=null),this.log("info","[AutoProxyCookie] Stopped")}getCurrentCookie(){return this.currentCookie}};function M(t){return new m(t)}function V(t){let{name:e="vite-auto-proxy-cookie",isDev:o,...r}=t,n=null;return{name:e,apply:"serve",async configureServer(i){n=M({...r,debug:t.debug??!1,autoRestart:t.autoRestart??!0,isDev:o});try{await n.setup(i)}catch(s){console.error("[vite-auto-proxy-cookie] Failed to setup proxy:",s),t.debug&&console.log("[vite-auto-proxy-cookie] Falling back to middleware mode")}},closeBundle(){n?.stop()}}}function W(t){let{cookieFile:e,debug:o=!1,onCookieChange:r,watch:n="auto",isDev:i}=t,s=null,a="",c=new u({cookieFile:e});return{name:"vite-dev-proxy-cookie",apply:"serve",configureServer(p){a=c.readCookie(),o&&console.log("[vite-dev-proxy-cookie] Initial cookie loaded");let h=p.middlewares||p._middlewares||p.app;h&&typeof h.use=="function"?h.use((l,f,P)=>{a&&l.url?.startsWith("/")&&(l.headers=l.headers||{},l.headers.cookie=a),P()}):console.warn("[vite-dev-proxy-cookie] Could not access middleware stack, cookie injection disabled");let g;i!==void 0?(g=i,o&&console.log(`[vite-dev-proxy-cookie] isDev=${i}, ${g?"enabling":"disabling"} watch`)):g=C(n,[],o,"[vite-dev-proxy-cookie]"),g?s=k(e,l=>{a=l,r?.(l),console.log("[vite-dev-proxy-cookie] Cookie changed, please restart server for full effect")},l=>{console.error("[vite-dev-proxy-cookie] Watch error:",l.message)}):o&&console.log("[vite-dev-proxy-cookie] File watch disabled")},closeBundle(){s?.stop()}}}import*as R from"path";function I(t,e={}){let{getCookie:o,debug:r=!1,headers:n={},ws:i=!1,changeOrigin:s=!0,secure:a=!1,onError:c}=e;return{ws:i,target:t,changeOrigin:s,secure:a,headers:n,onProxyReq:(h,g)=>{let l=o?o():"";if(l&&v(h,l),r){let f=g.url||"/";console.log("[Proxy Request]",f,g.method,l?"(with cookie)":"(no cookie)")}},onError:c||(h=>{console.error(`
3
+ [Proxy Error]`,h.message)})}}function he(t,e={}){let{watch:o="auto",debug:r=!1,productionEnvs:n=[],isDev:i}=e,s=new u({cookieFile:R.resolve(t)}),a;return i!==void 0?(a=i,r&&console.log(`[CookieFile] isDev=${i}, ${a?"enabling":"disabling"} watch`)):a=C(o,n,r,"[CookieFile]"),a?k(R.resolve(t),c=>{r&&console.log("[CookieFile] Updated:",c?"(has cookie)":"(empty)")},c=>{console.error("[CookieFile] Watch error:",c.message)}):r&&console.log("[CookieFile] File watch disabled"),()=>s.readCookie()}function pe(t){let{target:e,ignorePaths:o=[],includePaths:r=[],additionalProxies:n={},getCookie:i,debug:s,headers:a}=t,c={};if(r.length>0)for(let p of r)c[p]=I(e,{getCookie:i,debug:s,headers:a});else{let p={ws:!1,target:e,changeOrigin:!0,secure:!1,headers:a,onProxyReq:(h,g)=>{let l=g.url||"/";if(o.some(P=>l.startsWith(P)))return;let f=i?i():"";f&&v(h,f),s&&console.log("[Proxy Request]",l,g.method,f?"(with cookie)":"(no cookie)")},onError:h=>{console.error(`
4
+ [Proxy Error]`,h.message)}};c["/"]=p}for(let[p,h]of Object.entries(n))c[p]=I(h,{getCookie:i,debug:s,headers:a});return c}var b="",x=null;function S(){if(x!==null)return x;try{b=$("vite/package.json").version,x=parseInt(b.split(".")[0],10)}catch{x=5}return x}function fe(t){let{mode:e="auto",watch:o="auto",isDev:r,...n}=t,i=S();if(t.debug&&console.log(`[dev-proxy-cookie] Detected Vite ${i}.x`),e==="cookie"||e==="auto"&&!t.target)return W({cookieFile:t.cookieFile,debug:t.debug,onCookieChange:t.onCookieChange,watch:o,isDev:r});let s={cookieFile:t.cookieFile,target:t.target,debug:t.debug,autoRestart:t.autoRestart??!0,restartMarkerFile:t.restartMarkerFile,proxyMap:t.proxyMap,ignorePaths:t.ignorePaths};return V(s)}function ke(){return S(),b}function ye(){return S()}export{m as AutoProxyCookie,u as CookieReader,w as CookieWatcher,pe as createAutoProxyConfig,M as createAutoProxyCookie,N as createCookieGetter,fe as createDevProxyCookie,he as createFileCookieGetter,I as createVueProxyConfig,H as detectProductionEnvironment,ye as getViteMajorVersion,ke as getViteVersion,E as isProductionValue,C as shouldEnableWatch,V as viteAutoProxyCookie,W as viteDevProxyCookie,k as watchCookieFile};