I have a Nuxt project. Everything is OK when I generate a static page. However, I need to send a POST request to the other server.
I tried to use both a proxy in nuxt.config.js and just direct query, but after deploy to the ngnix eventually, nothing works.
Please help.
UPDATE. Steps to reproduce.
- Create Nuxt App including axios and proxy
- Configure your proxy for other webservice:
proxy: {
'/api': {
target: 'http://example.com:9000',
pathRewrite: {
'^/api': '/',
},
},
changeOrigin: true,
},
call this service somewhere in the code:
const result = await this.$axios.post('/api/email/subscribe', {email: email})
run "yarn dev" and test the service. It works locally properly.
- run 'nuxt generate' and deploy the static code hosting service, for example, hosting.com
- run your page which calls the above-mentioned service.
As a result, instead of making POST call to the hosting.com/api/email/subscribe
, it calls localhost:3000/api/email/subscribe
.