Using proxy-module and Axios module
proxy-module is the one-liner node.js http-proxy middleware solution for Nuxt.js using http-proxy-middleware
Axios-module is a secure and easy Axios integration with Nuxt.js.
$ yarn add @nuxtjs/axios @nuxtjs/proxy{
modules: [
'@nuxtjs/axios',
'@nuxtjs/proxy'
],
proxy: [
['/api/dog', { target: 'https://dog.ceo/', pathRewrite: { '^/api/dog': '/api/breeds/image/random' } }]
]
}async asyncData({ app }) {
const ip = await app.$axios.$get('http://icanhazip.com')
return { ip }
}More detail, please refer axios-module.