Skip to content

Commit 16c58d3

Browse files
committed
docs: improve readme
1 parent f35db51 commit 16c58d3

File tree

1 file changed

+43
-13
lines changed

1 file changed

+43
-13
lines changed

README.md

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
✓ ...See [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware) docs
2525

26-
⚠ Does not work in generated/static mode!
26+
⚠ Does not work with `nuxt generate` (see [static target](https://nuxtjs.org/docs/2.x/features/deployment-targets#static-hosting)).
2727

2828
## Setup
2929

@@ -39,22 +39,16 @@ yarn add @nuxtjs/proxy # or npm install @nuxtjs/proxy
3939
{
4040
modules: [
4141
// Simple usage
42-
'@nuxtjs/proxy',
43-
44-
// With options
45-
['@nuxtjs/proxy', { pathRewrite: { '^/api' : '/api/v1' } }]
46-
]
42+
'@nuxtjs/proxy'
43+
],
44+
proxy: {
45+
// see Proxy section
46+
}
4747
}
4848
```
4949

5050
- Define as many as proxy middleware you want in `proxy` section of `nuxt.config.js` (See [proxy](#proxy) section below)
5151

52-
## Options
53-
54-
- `changeOrigin` and `ws` options are enabled by default.
55-
56-
[optional] You can provide default options to all proxy targets by passing options to module options.
57-
5852
## `proxy`
5953

6054
You can provide proxy config using either object or array.
@@ -89,7 +83,10 @@ Keys are [context](https://github.com/chimurai/http-proxy-middleware#context-mat
8983
'/api': 'http://example.com',
9084

9185
// With options
92-
'/api2': { target: 'http://example.com', ws: false },
86+
'/api2': {
87+
target: 'http://example.com',
88+
ws: false
89+
},
9390

9491
// Proxy to backend unix socket
9592
'/api3': {
@@ -100,6 +97,39 @@ Keys are [context](https://github.com/chimurai/http-proxy-middleware#context-mat
10097
}
10198
```
10299

100+
## Default Options
101+
102+
- `changeOrigin` and `ws` options are enabled by default.
103+
104+
You can provide default options to all proxy targets by passing options to module options:
105+
106+
```js
107+
export default {
108+
modules: [
109+
// Disable ws option to all proxified endpoints
110+
['@nuxtjs/proxy', { ws: false }]
111+
],
112+
proxy: [
113+
'http://example.com/foo',
114+
'http://example.com:8000/api/books/*/**.json',
115+
]
116+
}
117+
```
118+
119+
This will be similar to:
120+
121+
```js
122+
export default {
123+
modules: [
124+
'@nuxtjs/proxy',
125+
],
126+
proxy: [
127+
['http://example.com/foo', { ws: false }],
128+
['http://example.com:8000/api/books/*/**.json', { ws: false }]
129+
]
130+
}
131+
```
132+
103133
## Development
104134

105135
1. Clone this repository

0 commit comments

Comments
 (0)