Skip to content

Commit

Permalink
docs: expand server.proxy description (#10831)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Nov 8, 2022
1 parent b8aa825 commit ff3eacf
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions docs/config/server-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ export default defineConfig({

- **Type:** `Record<string, string | ProxyOptions>`

Configure custom proxy rules for the dev server. Expects an object of `{ key: options }` pairs. If the key starts with `^`, it will be interpreted as a `RegExp`. The `configure` option can be used to access the proxy instance.
Configure custom proxy rules for the dev server. Expects an object of `{ key: options }` pairs. Any requests that request path starts with that key will be proxied to that specified target. If the key starts with `^`, it will be interpreted as a `RegExp`. The `configure` option can be used to access the proxy instance.

Note that if you are using non-relative [`base`](/config/shared-options.md#base), you must prefix each key with that `base`.

Uses [`http-proxy`](https://github.com/http-party/node-http-proxy). Full options [here](https://github.com/http-party/node-http-proxy#options).

Expand All @@ -89,15 +91,15 @@ In some cases, you might also want to configure the underlying dev server (e.g.
export default defineConfig({
server: {
proxy: {
// string shorthand
// string shorthand: http://localhost:5173/foo -> http://localhost:4567/foo
'/foo': 'http://localhost:4567',
// with options
// with options: http://localhost:5173/api/bar-> http://jsonplaceholder.typicode.com/bar
'/api': {
target: 'http://jsonplaceholder.typicode.com',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
},
// with RegEx
// with RegEx: http://localhost:5173/fallback/ -> http://jsonplaceholder.typicode.com/
'^/fallback/.*': {
target: 'http://jsonplaceholder.typicode.com',
changeOrigin: true,
Expand All @@ -111,9 +113,9 @@ export default defineConfig({
// proxy will be an instance of 'http-proxy'
}
},
// Proxying websockets or socket.io
// Proxying websockets or socket.io: ws://localhost:5173/socket.io -> ws://localhost:5174/socket.io
'/socket.io': {
target: 'ws://localhost:5173',
target: 'ws://localhost:5174',
ws: true
}
}
Expand Down

0 comments on commit ff3eacf

Please sign in to comment.