@gylautorun/dev-proxy-cookie 1.0.0 → 1.0.2

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,60 +0,0 @@
1
- import type { Plugin, ViteDevServer } from 'vite';
2
- import { CookieReader, CookieWatcher, watchCookieFile } from '../utils';
3
-
4
- export interface ViteDevProxyCookieOptions {
5
- cookieFile: string;
6
- debug?: boolean;
7
- onCookieChange?: (cookie: string) => void;
8
- }
9
-
10
- export function viteDevProxyCookie(options: ViteDevProxyCookieOptions): Plugin {
11
- const { cookieFile, debug = false, onCookieChange } = options;
12
- let watcher: CookieWatcher | null = null;
13
- let currentCookie: string = '';
14
-
15
- const cookieReader = new CookieReader({ cookieFile });
16
-
17
- return {
18
- name: 'vite-dev-proxy-cookie',
19
- apply: 'serve',
20
-
21
- configureServer(server: ViteDevServer) {
22
- currentCookie = cookieReader.readCookie();
23
- if (debug) {
24
- console.log('[vite-dev-proxy-cookie] Initial cookie loaded');
25
- }
26
-
27
- const middlewares = server.middlewares ||
28
- (server as any)._middlewares ||
29
- (server as any).app;
30
-
31
- if (middlewares && typeof middlewares.use === 'function') {
32
- middlewares.use((req: any, _res: any, next: any) => {
33
- if (currentCookie && req.url?.startsWith('/')) {
34
- req.headers = req.headers || {};
35
- req.headers['cookie'] = currentCookie;
36
- }
37
- next();
38
- });
39
- } else {
40
- console.warn('[vite-dev-proxy-cookie] Could not access middleware stack, cookie injection disabled');
41
- }
42
-
43
- watcher = watchCookieFile(
44
- cookieFile,
45
- (newCookie) => {
46
- currentCookie = newCookie;
47
- onCookieChange?.(newCookie);
48
- console.log('[vite-dev-proxy-cookie] Cookie changed, please restart server for full effect');
49
- },
50
- (error) => {
51
- console.error('[vite-dev-proxy-cookie] Watch error:', error.message);
52
- }
53
- );
54
- },
55
-
56
- closeBundle() {
57
- watcher?.stop();
58
- },
59
- };
60
- }
@@ -1,55 +0,0 @@
1
- import type { Plugin, ViteDevServer } from 'vite';
2
- import { AutoProxyCookie, createAutoProxyCookie, type AutoProxyCookieOptions } from './core';
3
-
4
- export interface ViteAutoProxyCookiePluginOptions extends AutoProxyCookieOptions {
5
- name?: string;
6
- }
7
-
8
- function getHttpServer(server: ViteDevServer): any {
9
- if ('httpServer' in server && server.httpServer) {
10
- return server.httpServer;
11
- }
12
- if ('_server' in server && server._server) {
13
- return server._server;
14
- }
15
- return null;
16
- }
17
-
18
- export function viteAutoProxyCookie(options: ViteAutoProxyCookiePluginOptions): Plugin {
19
- const {
20
- name = 'vite-auto-proxy-cookie',
21
- ...autoProxyOptions
22
- } = options;
23
-
24
- let autoProxy: AutoProxyCookie | null = null;
25
-
26
- return {
27
- name,
28
- apply: 'serve',
29
-
30
- async configureServer(server: ViteDevServer) {
31
- autoProxy = createAutoProxyCookie({
32
- ...autoProxyOptions,
33
- debug: options.debug ?? false,
34
- autoRestart: options.autoRestart ?? true,
35
- });
36
-
37
- try {
38
- await autoProxy.setup(server);
39
- } catch (error) {
40
- console.error('[vite-auto-proxy-cookie] Failed to setup proxy:', error);
41
-
42
- if (options.debug) {
43
- console.log('[vite-auto-proxy-cookie] Falling back to middleware mode');
44
- }
45
- }
46
- },
47
-
48
- closeBundle() {
49
- autoProxy?.stop();
50
- },
51
- };
52
- }
53
-
54
- export { AutoProxyCookie, createAutoProxyCookie };
55
- export type { AutoProxyCookieOptions };