Skip to content

A proxy plugin of vite. Which support router config like http-proxy-middleware

License

Notifications You must be signed in to change notification settings

luxueyan/vite-server-plugin-proxy

Repository files navigation

vite-server-plugin-proxy ⚡

npm node

This plugin support router config like http-proxy-middleware

Status

In rc.1 and will likely release 1.0 soon.

Getting Started

Install (yarn or npm)

yarn add vite-server-plugin-proxy or npm i vite-server-plugin-proxy

Usage

Example:

// vite.config.js
const defaultProxy = 'http://localhost:3000'
module.exports = {
  proxies: {
    '/api': {
      target: defaultProxy,
      proxyTimeout: 1500000,
      timeout: 1500000,
      changeOrigin: true,
      router: function (req) {
        if (req.query._proxy) {
          const proxyTarget = req.query._proxy
          return proxyTarget
        }

        console.log(req.path, `: proxy to ${defaultProxy}`)
        return defaultProxy
      },
    }
  }
}

License

MIT

About

A proxy plugin of vite. Which support router config like http-proxy-middleware

Resources

License

Stars

Watchers

Forks

Packages

No packages published