nuxt-proxy
Http-proxy middleware for Nuxt and h3.
Before using
Check out H3's built-in proxyRequest helper before using this module.
Installation
npm install nuxt-proxy
Usage
export default defineNuxtConfig({
modules: ['nuxt-proxy'],
proxy: {
options: {
target: 'https://jsonplaceholder.typicode.com',
changeOrigin: true,
pathRewrite: {
'^/api/todos': '/todos',
'^/api/users': '/users'
},
pathFilter: [
'/api/todos',
'/api/users'
]
}
},
})
<script setup>
const { data } = useFetch('http://localhost:3000/api/todos')
</script>
You can pass an array of options for multiple targets.
Runtime config
NUXT_PROXY_OPTIONS_TARGET=https://reqres.in/api
export default defineNuxtConfig({
modules: ['nuxt-proxy'],
runtimeConfig: {
proxy: {
options: { target: 'https://jsonplaceholder.typicode.com', ...{ } }
}
}
})
License
MIT