Awesome
When developing frontend applications with Vite, there is often a need to interact with multiple backend servers, such as mock environments, testing environments, and production environments. To simplify this process, I have created a tool called the "Vite Dynamic Reverse Proxy Plugin." This plugin can dynamically set reverse proxies based on URL parameters (?debug=URL
), allowing you to easily switch between different development and testing environments without manual proxy configuration.
中文文档
Key Features
- Dynamic Proxy Configuration: Automatically configure reverse proxies based on URL parameters, eliminating the need to manually modify the Vite configuration file.
- Simple and Easy to Use: Install the plugin and provide the required parameters to seamlessly integrate it into your Vite project.
- Flexibility: Supports flexible switching of proxy targets during development to adapt to different testing environments.
How to Use
-
Install the plugin:
npm install vite-plugin-debug-proxy
-
Use the plugin in your Vite configuration file:
// vite.config.js import dynamicProxy from 'vite-plugin-debug-proxy'; export default { // ...other configuration plugins: [ // ... dynamicProxy({ path:new RegExp("^/api")//use RegExp //path:"/api" //use string path }), ], };
-
When accessing your application, you can automatically set the proxy target using URL parameters. For example:
- Accessing
http://localhost:3000?debug=https://192.168.1.123:8080/
will proxy all requests fromhttp://localhost:3000/api/*
tohttps://192.168.1.123:8080/*
.
- Accessing
This "Vite Dynamic Reverse Proxy Plugin" will greatly simplify the configuration of backend interactions during development, allowing you to switch between different environments effortlessly. No manual proxy settings are required. If you have any questions or suggestions, please feel free to reach out.