@nuxtjs/proxy
Version:
proxy support for nuxt server
127 lines (84 loc) ⢠2.99 kB
Markdown
for nuxt server
[š **Release Notes**](./CHANGELOG.md)
ā Path rewrites
ā Host based router (useful for staging/test)
ā Logs / Proxy Events
ā WebSockets
ā Auth / Cookie
ā ...See [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware) docs
ā Does not work in generated/static mode!
## Setup
1. Add `@nuxtjs/proxy` dependency to your project
```bash
yarn add @nuxtjs/proxy # or npm install @nuxtjs/proxy
```
2. Add `@nuxtjs/proxy` to the `modules` section of `nuxt.config.js`
```js
{
modules: [
// Simple usage
'@nuxtjs/proxy',
// With options
['@nuxtjs/proxy', { pathRewrite: { '^/api' : '/api/v1' } }]
]
}
```
- Define as many as proxy middleware you want in `proxy` section of `nuxt.config.js` (See [proxy](
- `changeOrigin` and `ws` options are enabled by default.
[ ] You can provide default options to all proxy targets by passing options to module options.
You can provide proxy config using either object or array.
You can use [shorthand syntax](https://github.com/chimurai/http-proxy-middleware#shorthand) to configure proxy:
```js
{
proxy: [
// Proxies /foo to http://example.com/foo
'http://example.com/foo',
// Proxies /api/books/*/**.json to http://example.com:8000
'http://example.com:8000/api/books/*/**.json',
// You can also pass more options
[ 'http://example.com/foo', { ws: false } ]
]
}
```
Keys are [context](https://github.com/chimurai/http-proxy-middleware#context-matching)
```js
{
proxy: {
// Simple proxy
'/api': 'http://example.com',
// With options
'/api2': { target: 'http://example.com', ws: false },
// Proxy to backend unix socket
'/api3': {
changeOrigin: false,
target: { socketPath: '/var/run/http-sockets/backend.sock' }
}
}
}
```
1. Clone this repository
2. Install dependencies using `yarn install` or `npm install`
3. Start development server using `npm run dev`
[ ](./LICENSE)
Copyright (c) Nuxt Community
<!-- Badges -->
[ ]: https://img.shields.io/npm/v/@nuxtjs/proxy/latest.svg?style=flat-square
[ ]: https://npmjs.com/package/@nuxtjs/proxy
[ ]: https://img.shields.io/npm/dt/@nuxtjs/proxy.svg?style=flat-square
[ ]: https://npmjs.com/package/@nuxtjs/proxy
[ ]: https://img.shields.io/codecov/c/github/nuxt-community/proxy-module.svg?style=flat-square
[ ]: https://codecov.io/gh/nuxt-community/proxy-module
[ ]: https://img.shields.io/npm/l/@nuxtjs/proxy.svg?style=flat-square
[ ]: https://npmjs.com/package/@nuxtjs/proxy
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![codecov][codecov-src]][codecov-href]
[![license][license-src]][license-href]
> Proxy support