@nuxtjs/proxy

Proxy support for nuxt server
📖 Release Notes
Features
✓ Path rewrites
✓ Host based router (useful for staging/test)
✓ Logs / Proxy Events
✓ WebSockets
✓ Auth / Cookie
✓ ...See http-proxy-middleware docs
⚠ Does not work in generated/static mode!
Setup
- Add
@nuxtjs/proxy dependency to your project
yarn add @nuxtjs/proxy
- Add
@nuxtjs/proxy to the modules section of nuxt.config.js
{
modules: [
'@nuxtjs/proxy',
['@nuxtjs/proxy', { pathRewrite: { '^/api' : '/api/v1' } }]
]
}
- Define as many as proxy middleware you want in
proxy section of nuxt.config.js (See proxy section below)
Options
changeOrigin and ws options are enabled by default.
[optional] You can provide default options to all proxy targets by passing options to module options.
proxy
You can provide proxy config using either object or array.
Array Config
You can use shorthand syntax to configure proxy:
{
proxy: [
'http://example.com/foo',
'http://example.com:8000/api/books/*/**.json',
[ 'http://example.com/foo', { ws: false } ]
]
}
Object Config
Keys are context
{
proxy: {
'/api': 'http://example.com',
'/api2': { target: 'http://example.com', ws: false },
'/api3': {
changeOrigin: false,
target: { socketPath: '/var/run/http-sockets/backend.sock' }
}
}
}
Development
- Clone this repository
- Install dependencies using
yarn install or npm install
- Start development server using
npm run dev
License
MIT License
Copyright (c) Nuxt Community