@@ -17,16 +17,18 @@ export default defineNuxtConfig({
17
17
modules: [' nuxt-proxy' ],
18
18
// See options here https://github.com/chimurai/http-proxy-middleware#options
19
19
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
+ }
30
32
}
31
33
})
32
34
@@ -41,6 +43,45 @@ const { data } = useFetch('http://localhost:3000/api/todos')
41
43
</script >
42
44
```
43
45
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
+
44
85
## License
45
86
46
87
MIT
0 commit comments