# vite-plugin-proxy

> > what `devServer.proxy` is for `webpack-dev-server`, `vite-plugin-proxy` is for `vite`

Latest version **0.5.0** (published 2020-05-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install vite-plugin-proxy
pnpm add vite-plugin-proxy
yarn add vite-plugin-proxy
bun add vite-plugin-proxy
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.0 |
| Published | 2020-05-11 |
| First published | 2020-05-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 2.2 KB |
| Known vulnerabilities | 0 (+4 in 1 direct dependencies) |
| Install scripts | no |
| Author | ziga.dev |
| Maintainers | zigomir |
| Keywords | vite, vue, proxy |

## Links

- npm: https://www.npmjs.com/package/vite-plugin-proxy
- Homepage: https://github.com/zigomir/vite-plugin-proxy
- npm.io page: https://npm.io/package/vite-plugin-proxy

## Dependencies (2)

- [koa2-connect](https://npm.io/package/koa2-connect.md) ^1.0.2
- [http-proxy-middleware](https://npm.io/package/http-proxy-middleware.md) ^1.0.3

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 0.5.0 (latest) — 2020-05-11
- 0.4.0 — 2020-05-06
- 0.3.0 — 2020-05-03
- 0.2.0 — 2020-05-03
- 0.1.0 — 2020-05-03

## README

# vite-plugin-proxy

> what `devServer.proxy` is for `webpack-dev-server`, `vite-plugin-proxy` is for `vite`

> it's a `vite` plugin that proxies your requests

## usage

> also see [/example](/example) dir

```sh
npm install vite-plugin-proxy --save-dev
# or
yarn add -D vite-plugin-proxy
```

```js
// vite.config.js # or vite.config.ts
const proxyPlugin = require('vite-plugin-proxy')

module.exports = {
  plugins: [
    proxyPlugin({
      '/api': {
        // for option docs see https://github.com/chimurai/http-proxy-middleware#options
        target: 'https://reqres.in',
        changeOrigin: true,
        onProxyRes: (proxyRes) => {
          // cache all responses for faster development
          // use browser's "Disable cache" in dev tools when you need to update API responses
          proxyRes.headers['Cache-Control'] = `public, max-age=${ONE_YEAR_IN_SECONDS}`
          // delete headers you don't want
          delete proxyRes.headers['expires']
        },
      },
    }),
  ],
}
```

## credit

mostly shamelessly stolen from https://github.com/sunyongjian/koa2-proxy-middleware

---
_Source: https://npm.io/package/vite-plugin-proxy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
