Home

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

How to Use

  1. Install the plugin:

    npm install vite-plugin-debug-proxy
    
  2. 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
        }),
      ],
    };
    
  3. 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 from http://localhost:3000/api/* to https://192.168.1.123:8080/*.

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.