{"_id":"@dhlx/uni-vite-static-proxy","_rev":"6-54f727d16420a958c0722d87785f2fc8","name":"@dhlx/uni-vite-static-proxy","dist-tags":{"latest":"0.0.6"},"versions":{"0.0.1":{"name":"@dhlx/uni-vite-static-proxy","version":"0.0.1","_id":"@dhlx/uni-vite-static-proxy@0.0.1","maintainers":[{"name":"lidenghui~","email":"3379489032@qq.com"}],"dist":{"shasum":"3560ad577191f1b97e4cd1b58754a3b01b37df1a","tarball":"https://registry.npmjs.org/@dhlx/uni-vite-static-proxy/-/uni-vite-static-proxy-0.0.1.tgz","fileCount":7,"integrity":"sha512-tGWraqr+PIFMgx8n36Cw4FxlkXf2QkboQvUk9VcuIyCguBt5RgzVZczy5uBZN9ETHfUbOX2zS3El4YxdwGSojw==","signatures":[{"sig":"MEQCICBWfkGThpa7dTLGYyRWxP1zjcGhqPDPZ1jNlPjGLzkOAiAmEhMcq7joJpKk8ZzSTzaNf31mcDDHcHCXFlB0O8Wing==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":10361},"main":"./dist/index.umd.cjs","type":"module","types":"./dist/lib/main.d.ts","module":"./dist/index.js","exports":{"types":"./dist/lib/main.d.ts","import":"./dist/index.js","require":"./dist/index.umd.cjs"},"private":false,"scripts":{"dev":"vite -c vite-test.config.ts","test":"ava","build":"tsc && vite build"},"_npmUser":{"name":"lidenghui~","email":"3379489032@qq.com"},"repository":{"url":""},"_npmVersion":"11.1.0","description":"`@dhlx/uni-vite-static-proxy` is a Vite plugin that provides an easy way to serve static files and configure proxy middleware using Express. It also includes a caching mechanism to control server restart behavior.","directories":{},"_nodeVersion":"22.13.1","dependencies":{"@dhlx/delay":"^0.0.5","vite-plugin-dts":"^4.2.2"},"_hasShrinkwrap":false,"devDependencies":{"ava":"^6.1.3","vite":"^5.2.10","prettier":"^3.3.3","typescript":"^5.4.5","@types/express":"^5.0.0"},"peerDependencies":{"express":"^4.21.2","http-proxy-middleware":"^3.0.3"},"_npmOperationalInternal":{"tmp":"tmp/uni-vite-static-proxy_0.0.1_1741151766729_0.77765259114782","host":"s3://npm-registry-packages-npm-production"}},"0.0.2":{"name":"@dhlx/uni-vite-static-proxy","version":"0.0.2","_id":"@dhlx/uni-vite-static-proxy@0.0.2","maintainers":[{"name":"lidenghui~","email":"3379489032@qq.com"}],"dist":{"shasum":"9f00daa9e98d62199ebb6899d0bdc9d248547d3d","tarball":"https://registry.npmjs.org/@dhlx/uni-vite-static-proxy/-/uni-vite-static-proxy-0.0.2.tgz","fileCount":7,"integrity":"sha512-76+EShV+p+ZvHlmJVVQ8XIJWQ6XcGdeef+QVhckfUZi0qWHSaAB2oxyi6JfJkyd8vPDzQFZr0p4B1HcB4KPVBw==","signatures":[{"sig":"MEYCIQCqm81UjkdHchzbJqaifpWpvbsg3rbySXHFbgiQXC079wIhAPpYQmSjnDwvGJqleaOEHIJHn/WZkJ/B61TtYhmzWwBF","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":10090},"main":"./dist/index.umd.cjs","type":"module","types":"./dist/lib/main.d.ts","module":"./dist/index.js","exports":{"types":"./dist/lib/main.d.ts","import":"./dist/index.js","require":"./dist/index.umd.cjs"},"private":false,"scripts":{"dev":"vite -c vite-test.config.ts","test":"ava","build":"tsc && vite build"},"_npmUser":{"name":"lidenghui~","email":"3379489032@qq.com"},"repository":{"url":""},"_npmVersion":"11.1.0","description":"`@dhlx/uni-vite-static-proxy` is a Vite plugin that provides an easy way to serve static files and configure proxy middleware using Express. It also includes a caching mechanism to control server restart behavior.","directories":{},"_nodeVersion":"22.13.1","dependencies":{"@dhlx/delay":"^0.0.5","vite-plugin-dts":"^4.2.2"},"_hasShrinkwrap":false,"devDependencies":{"ava":"^6.1.3","vite":"^5.2.10","prettier":"^3.3.3","typescript":"^5.4.5","@types/express":"^5.0.0"},"peerDependencies":{"express":"^4.21.2","http-proxy-middleware":"^3.0.3"},"_npmOperationalInternal":{"tmp":"tmp/uni-vite-static-proxy_0.0.2_1741163232901_0.4491921299326438","host":"s3://npm-registry-packages-npm-production"}},"0.0.3":{"name":"@dhlx/uni-vite-static-proxy","version":"0.0.3","_id":"@dhlx/uni-vite-static-proxy@0.0.3","maintainers":[{"name":"lidenghui~","email":"3379489032@qq.com"}],"dist":{"shasum":"f45994db8a5836a3a199b1f1fcddc29132825698","tarball":"https://registry.npmjs.org/@dhlx/uni-vite-static-proxy/-/uni-vite-static-proxy-0.0.3.tgz","fileCount":7,"integrity":"sha512-f6vz+r47N/2i33K3RPVCDrelQSE62Nlcrve+bh7H4levg0flN9cVVJHNwEdTgLZT5pchAvknScDLHMtAEuFVgg==","signatures":[{"sig":"MEUCIQC6urJ18EbD3Bu4gOozcnwA1guTmnTyApEN4FSmWDYxBQIgT+l/XQmmMJ0wY6afvCtYnHNOhJq7e8m9y8vTdJrsYHc=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":10037},"main":"./dist/index.umd.cjs","type":"module","types":"./dist/lib/main.d.ts","module":"./dist/index.js","exports":{"types":"./dist/lib/main.d.ts","import":"./dist/index.js","require":"./dist/index.umd.cjs"},"private":false,"scripts":{"dev":"vite -c vite-test.config.ts","test":"ava","build":"tsc && vite build"},"_npmUser":{"name":"lidenghui~","email":"3379489032@qq.com"},"repository":{"url":""},"_npmVersion":"11.1.0","description":"`@dhlx/uni-vite-static-proxy` is a Vite plugin that provides an easy way to serve static files and configure proxy middleware using Express. It also includes a caching mechanism to control server restart behavior.","directories":{},"_nodeVersion":"22.13.1","dependencies":{"@dhlx/delay":"^0.0.5","vite-plugin-dts":"^4.2.2"},"_hasShrinkwrap":false,"devDependencies":{"ava":"^6.1.3","vite":"^5.2.10","prettier":"^3.3.3","typescript":"^5.4.5","@types/express":"^5.0.0"},"peerDependencies":{"express":"^4.21.2","http-proxy-middleware":"^3.0.3"},"_npmOperationalInternal":{"tmp":"tmp/uni-vite-static-proxy_0.0.3_1741163946310_0.3274973275396882","host":"s3://npm-registry-packages-npm-production"}},"0.0.4":{"name":"@dhlx/uni-vite-static-proxy","version":"0.0.4","keywords":["uni-app","vite","static","proxy","service"],"_id":"@dhlx/uni-vite-static-proxy@0.0.4","maintainers":[{"name":"lidenghui~","email":"3379489032@qq.com"}],"homepage":"https://github.com/LiDengHui/uni-vite-static-proxy#readme","bugs":{"url":"https://github.com/LiDengHui/uni-vite-static-proxy/issues"},"dist":{"shasum":"0202c1df506cd403c28083092226cff058c29f10","tarball":"https://registry.npmjs.org/@dhlx/uni-vite-static-proxy/-/uni-vite-static-proxy-0.0.4.tgz","fileCount":7,"integrity":"sha512-rK96txRWnZvO4IU5EYCcb+tP8Ab5EAcnL9V1QjUWW+I/Obm0fnOWmY6HcHO2l05Kp/gBhYf/Nd/dHbZorCnkzQ==","signatures":[{"sig":"MEYCIQC/x/R2Mv7tW2FFVNRJ4AmePCatp8SVymTrLUwNYt+kzgIhANhBtOi9MHcPoTtPcPqn78NIRQmc/O1GumpAWbgZ/JxP","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":10315},"main":"./dist/index.umd.cjs","type":"module","types":"./dist/lib/main.d.ts","module":"./dist/index.js","exports":{"types":"./dist/lib/main.d.ts","import":"./dist/index.js","require":"./dist/index.umd.cjs"},"private":false,"scripts":{"dev":"vite -c vite-test.config.ts","test":"ava","build":"tsc && vite build"},"_npmUser":{"name":"lidenghui~","email":"3379489032@qq.com"},"repository":{"url":"git+https://github.com/LiDengHui/uni-vite-static-proxy.git","type":"git"},"_npmVersion":"11.1.0","description":"uni-app Enable local static file server with proxy forwarding","directories":{},"_nodeVersion":"22.13.1","dependencies":{"@dhlx/delay":"^0.0.5","vite-plugin-dts":"^4.2.2"},"_hasShrinkwrap":false,"devDependencies":{"ava":"^6.1.3","vite":"^5.2.10","prettier":"^3.3.3","typescript":"^5.4.5","@types/express":"^5.0.0"},"peerDependencies":{"express":"^4.21.2","http-proxy-middleware":"^3.0.3"},"_npmOperationalInternal":{"tmp":"tmp/uni-vite-static-proxy_0.0.4_1741164781440_0.5504482119388241","host":"s3://npm-registry-packages-npm-production"}},"0.0.5":{"name":"@dhlx/uni-vite-static-proxy","version":"0.0.5","keywords":["uni-app","vite","static","proxy","service"],"_id":"@dhlx/uni-vite-static-proxy@0.0.5","maintainers":[{"name":"lidenghui~","email":"3379489032@qq.com"}],"homepage":"https://github.com/LiDengHui/uni-vite-static-proxy#readme","bugs":{"url":"https://github.com/LiDengHui/uni-vite-static-proxy/issues"},"dist":{"shasum":"e4fb38147517404afebce28f07bd60860648e45a","tarball":"https://registry.npmjs.org/@dhlx/uni-vite-static-proxy/-/uni-vite-static-proxy-0.0.5.tgz","fileCount":7,"integrity":"sha512-5C9icCAvSQxJ+wVfEDiFxv+JnIRXpriMu9uGFOSidAUNOJg15ADpfKco1AyKD8Oz4K4kJh0WwLppoBgtVhpe8g==","signatures":[{"sig":"MEUCICy7oIwuak5e3DIuepuRJyL69dXgGweR1MEYMjn1osKJAiEA1DsAcACj7DdaYAaOEb0fJ9AdnSaVFNeglsdmUXZ1++8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":10983},"main":"./dist/index.umd.cjs","type":"module","types":"./dist/lib/main.d.ts","module":"./dist/index.js","exports":{"types":"./dist/lib/main.d.ts","import":"./dist/index.js","require":"./dist/index.umd.cjs"},"gitHead":"3397620120719593a7d0fbdcdd517980e076fc8f","private":false,"scripts":{"dev":"vite -c vite-test.config.ts","test":"ava","build":"tsc && vite build"},"_npmUser":{"name":"lidenghui~","email":"3379489032@qq.com"},"repository":{"url":"git+https://github.com/LiDengHui/uni-vite-static-proxy.git","type":"git"},"_npmVersion":"11.1.0","description":"uni-app Enable local static file server with proxy forwarding","directories":{},"_nodeVersion":"22.13.1","dependencies":{"@dhlx/delay":"^0.0.5","vite-plugin-dts":"^4.2.2"},"_hasShrinkwrap":false,"devDependencies":{"ava":"^6.1.3","vite":"^5.2.10","prettier":"^3.3.3","typescript":"^5.4.5","@types/express":"^5.0.0"},"peerDependencies":{"express":"^4.21.2","body-parser":"^1.20.3","http-proxy-middleware":"^3.0.3"},"_npmOperationalInternal":{"tmp":"tmp/uni-vite-static-proxy_0.0.5_1741501002035_0.14423957436916512","host":"s3://npm-registry-packages-npm-production"}},"0.0.6":{"name":"@dhlx/uni-vite-static-proxy","private":false,"version":"0.0.6","type":"module","main":"./dist/main.cjs","module":"./dist/main.js","types":"./dist/main.d.ts","exports":{"types":"./dist/main.d.ts","import":"./dist/main.js","require":"./dist/main.cjs"},"scripts":{"dev":"vite -c vite-test.config.ts","build":"tsc && vite build","test":"ava"},"devDependencies":{"@types/express":"^5.0.0","ava":"^6.1.3","prettier":"^3.3.3","typescript":"^5.4.5","vite":"^5.2.10"},"dependencies":{"@dhlx/delay":"^0.0.5","vite-plugin-dts":"^4.2.2"},"peerDependencies":{"express":"^4.21.2","http-proxy-middleware":"^3.0.3"},"repository":{"type":"git","url":"git+https://github.com/LiDengHui/uni-vite-static-proxy.git"},"description":"uni-app Enable local static file server with proxy forwarding","keywords":["uni-app","vite","static","proxy","service"],"_id":"@dhlx/uni-vite-static-proxy@0.0.6","gitHead":"3397620120719593a7d0fbdcdd517980e076fc8f","bugs":{"url":"https://github.com/LiDengHui/uni-vite-static-proxy/issues"},"homepage":"https://github.com/LiDengHui/uni-vite-static-proxy#readme","_nodeVersion":"22.17.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-RlUzVXpIpzpdfQQJMEgmkwjv33Bgrrm9DqvWBEXQKYdS9j1uE2oFtFAD10ZyUc3H4kNhrRxXPAkqEiWxcWfMqA==","shasum":"f63e62c12c698ef496df93f8c3d014c787aa0586","tarball":"https://registry.npmjs.org/@dhlx/uni-vite-static-proxy/-/uni-vite-static-proxy-0.0.6.tgz","fileCount":6,"unpackedSize":11751,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIDIAiYWBTshRfDQCnsr5JZVUywOCPSjm+aD3upW6Vl8YAiB5Dhdtg24t+CNXCHstQFx9tLFhjp9ezMpFlzlCLLfTng=="}]},"_npmUser":{"name":"lidenghui~","email":"3379489032@qq.com"},"directories":{},"maintainers":[{"name":"lidenghui~","email":"3379489032@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/uni-vite-static-proxy_0.0.6_1752985337415_0.8601826869870115"},"_hasShrinkwrap":false}},"time":{"created":"2025-03-05T05:16:06.638Z","modified":"2025-07-20T04:22:17.824Z","0.0.1":"2025-03-05T05:16:06.962Z","0.0.2":"2025-03-05T08:27:13.059Z","0.0.3":"2025-03-05T08:39:06.488Z","0.0.4":"2025-03-05T08:53:01.604Z","0.0.5":"2025-03-09T06:16:42.203Z","0.0.6":"2025-07-20T04:22:17.606Z"},"bugs":{"url":"https://github.com/LiDengHui/uni-vite-static-proxy/issues"},"homepage":"https://github.com/LiDengHui/uni-vite-static-proxy#readme","keywords":["uni-app","vite","static","proxy","service"],"repository":{"type":"git","url":"git+https://github.com/LiDengHui/uni-vite-static-proxy.git"},"description":"uni-app Enable local static file server with proxy forwarding","maintainers":[{"name":"lidenghui~","email":"3379489032@qq.com"}],"readme":"\n# @dhlx/uni-vite-static-proxy\n\n`@dhlx/uni-vite-static-proxy` is a Vite plugin that provides an easy way to serve static files and configure proxy middleware using Express. It also includes a caching mechanism to control server restart behavior.\n\n## Features\n- Static file serving using Express.\n- Proxy middleware configuration to redirect requests to external targets.\n- Caching and key management to control server restart behavior.\n- Supports multiple proxy configurations.\n\n## Installation\n\nTo install the plugin in your Vite project, run the following command:\n\n```bash\nnpm install @dhlx/uni-vite-static-proxy --save-dev\n```\n\nor using `pnpm`:\n\n```bash\npnpm add @dhlx/uni-vite-static-proxy --dev\n```\n\n## Usage\n\n### Basic Usage\n\n1. Import the plugin in your `vite.config.ts` or `vite.config.js` file:\n\n```ts\nimport uniViteStaticProxy from '@dhlx/uni-vite-static-proxy';\n```\n\n2. Configure the plugin in the `plugins` array of your Vite config:\n\n```ts\nimport { defineConfig } from 'vite';\nimport uniViteStaticProxy from '@dhlx/uni-vite-static-proxy';\n\nexport default defineConfig({\n  plugins: [\n    uniViteStaticProxy({\n      port: 3000, // Port for the Express server\n      staticPath: 'path/to/static/files', // Static files directory to be served\n      proxyConfigs: [\n        {\n          pathFilter: '/api', // Path to match for the proxy\n          target: 'https://api.example.com', // Target server for the proxy\n          pathRewrite: {\n            '^/api': '', // Optional: Rewrite paths before proxying\n          },\n        },\n        // Add more proxy configurations as needed\n      ],\n    }),\n  ],\n});\n```\n\n### Configuration Options\n\n- `port` (default: `3000`): The port on which the Express server will listen.\n- `staticPath` (default: `''`): The path to the directory containing static files to serve. If provided, the plugin will serve these files using Express.\n- `proxyConfigs` (default: `[]`): An array of objects for configuring proxy rules. Each object should have:\n    - `pathFilter`: A string or regex for the path to match.\n    - `target`: The target server URL where the requests should be proxied.\n    - `pathRewrite` (optional): An object specifying path rewrite rules.\n\n### Caching Mechanism\n\nThe plugin uses a caching file (`_catch.json`) to manage server restart behavior. It tracks the state of the server and prevents restarting if the server was previously opened. You can use the following functions to interact with the cache:\n\n- `setCache(key: string, value: string)`: Sets a cache value for a given key.\n- `getCache(key?: string)`: Gets the cache value for the given key or the entire cache if no key is provided.\n- `getLastKey()`: Gets the last cache key used.\n- `removeKey(key: string)`: Removes a cache key.\n\n## Commands\n\n### `npm run dev` or `vite`\n\nWhen running the Vite development server, the plugin will automatically start the Express server for handling static files and proxies.\n\n### Graceful Shutdown\n\nThe plugin supports graceful shutdown. When the Vite server is restarted or terminated, the Express server will also be closed.\n\n### Handling Server Errors\n\nIf the Express server encounters an error, it will log the error message.\n\n## Example\n\nHere’s an example of a `vite.config.ts` file using the plugin:\n\n```ts\nimport { defineConfig } from 'vite';\nimport uniViteStaticProxy from 'uni-vite-static-proxy';\n\nexport default defineConfig({\n  plugins: [\n    uniViteStaticProxy({\n      port: 4000,\n      staticPath: 'public',\n      proxyConfigs: [\n        {\n          pathFilter: '/api',\n          target: 'https://api.example.com',\n        },\n      ],\n    }),\n  ],\n});\n```\n\nThis configuration will start an Express server on port 4000, serve static files from the `public` directory, and proxy requests to `/api` to `https://api.example.com`.\n\n## License\n\nMIT License.\n","readmeFilename":"README.md"}