You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

vite-dynamic-proxy

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-dynamic-proxy

A Vite plugin that enables dynamic proxy configuration at runtime, allowing flexible and configurable proxy settings for development servers

1.1.0
latest
Source
npmnpm
Version published
Weekly downloads
571
-5.31%
Maintainers
1
Weekly downloads
 
Created
Source

vite-dynamic-proxy

npm version CI License: ISC TypeScript

A Vite plugin that enables dynamic proxy configuration at runtime, allowing you to change proxy target using URL query parameters without restarting the development server.

Installation

npm install vite-dynamic-proxy

Usage

Basic Configuration

// vite.config.ts
import { defineConfig } from 'vite'
import { dynamicProxyPlugin } from 'vite-dynamic-proxy'

export default defineConfig({
  plugins: [
    dynamicProxyPlugin({
      // Required: Default target URL for the proxy
      defaultTarget: 'http://localhost:3000',
      
      // Required: Path to proxy (e.g., '/api' or '^/api')
      path: '/api',
      
      // Optional: Change origin header (default: true)
      changeOrigin: true
    })
  ]
})

Configuration Options

OptionTypeDescriptionDefault
defaultTargetstringDefault target URL for the proxy (required)-
pathstringPath to proxy, can be a simple path or regex starting with ^ (required)-
changeOriginbooleanChanges the origin of the host headertrue

Dynamic Proxy Target

You can change the proxy target at runtime by adding a debug query parameter to your URL. The plugin supports both HTTP and HTTPS targets:

# Using HTTP
http://localhost:5173/your-app?debug=localhost:3001

# Using explicit HTTP
http://localhost:5173/your-app?debug=http://localhost:3001

# Using HTTPS
http://localhost:5173/your-app?debug=https://api.example.com

When using HTTPS targets, the plugin automatically sets secure: false to allow self-signed certificates.

Path Matching Examples

// Simple path matching
dynamicProxyPlugin({
  defaultTarget: 'http://localhost:3000',
  path: '/api'  // Will match paths starting with /api
})

// Regex path matching
dynamicProxyPlugin({
  defaultTarget: 'http://localhost:3000',
  path: '^/api'  // Will match paths using regex pattern
})

Development

  • npm install - Install dependencies
  • npm run build - Build the plugin
  • npm run test - Run tests
  • npm run test:coverage - Run tests with coverage
  • npm run lint - Run ESLint
  • npm run typecheck - Run TypeScript type checking

License

ISC

Keywords

vite

FAQs

Package last updated on 07 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts