Skip to content

Commit e9921fc

Browse files
committed
update readme
1 parent 2011441 commit e9921fc

File tree

1 file changed

+51
-10
lines changed

1 file changed

+51
-10
lines changed

README.md

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ export default defineNuxtConfig({
1717
modules: ['nuxt-proxy'],
1818
// See options here https://github.com/chimurai/http-proxy-middleware#options
1919
proxy: {
20-
target: 'https://jsonplaceholder.typicode.com',
21-
changeOrigin: true,
22-
pathRewrite: {
23-
'^/api/todos': '/todos',
24-
'^/api/users': '/users'
25-
},
26-
pathFilter: [
27-
'/api/todos',
28-
'/api/users'
29-
]
20+
options: {
21+
target: 'https://jsonplaceholder.typicode.com',
22+
changeOrigin: true,
23+
pathRewrite: {
24+
'^/api/todos': '/todos',
25+
'^/api/users': '/users'
26+
},
27+
pathFilter: [
28+
'/api/todos',
29+
'/api/users'
30+
]
31+
}
3032
}
3133
})
3234

@@ -41,6 +43,45 @@ const { data } = useFetch('http://localhost:3000/api/todos')
4143
</script>
4244
```
4345

46+
Multiple targets
47+
48+
```ts
49+
export default defineNuxtConfig({
50+
modules: ['nuxt-proxy'],
51+
// See options here https://github.com/chimurai/http-proxy-middleware#options
52+
proxy: {
53+
options: [
54+
{
55+
target: 'https://jsonplaceholder.typicode.com',
56+
changeOrigin: true,
57+
pathRewrite: {
58+
'^/api/todos': '/todos',
59+
'^/api/users': '/users'
60+
},
61+
pathFilter: [
62+
'/api/todos',
63+
'/api/users'
64+
]
65+
},
66+
{
67+
target: 'https://api.spacexdata.com/v5',
68+
changeOrigin: true,
69+
pathRewrite: {
70+
'^/api/launches': '/launches/latest',
71+
},
72+
pathFilter: [
73+
'/api/launches',
74+
],
75+
},
76+
]
77+
}
78+
})
79+
80+
// GET /api/todos -> https://jsonplaceholder.typicode.com/todos [304]
81+
// GET /api/users -> https://jsonplaceholder.typicode.com/users [304]
82+
// GET /api/launches -> https://api.spacexdata.com/v5/launches/latest [304]
83+
```
84+
4485
## License
4586

4687
MIT

0 commit comments

Comments
 (0)