POST requests with payload are not send to endpoint
zajca opened this issue · comments
I run into this problem.
When I have proxy set like this:
proxy: {
'/api/':{ target: process.env.API_URL, pathRewrite: {'^/api/': ''}, logLevel: 'debug' }
},
axios: {
proxy: true
},
when I send post to url is processed by backed just fine
this.$axios.$post('/api/non-existing-url') -> 404
But when i set payload like this:
this.$axios.$post('/jh-api/non-existing-url', {
form': {}
})
->
Request failed with status code 504
✖ error nuxt › proxy › [HPM] Error occurred while trying to proxy request non-existing-url from localhost:3000 to http://127.0.0.1:8082 (ECONNRESET) (https://nodejs.org/api/errors.html#errors_common_system_errors)
proxy-module: 1.3.1
nuxtjs/axios: 5.3.4
nuxt: 2.2.0
This issue as been imported as question since it does not respect proxy-module issue template. Only bug reports and feature requests stays open to reduce maintainers workload.
If your issue is not a question, please mention the repo admin or moderator to change its type and it will be re-opened automatically.
Your question is available at https://cmty.app/nuxt/proxy-module/issues/c11.
I fixed, with workaround of official github
I fixed this issue by 'coexist-parser-proxy'. You should put it above bodyParser in nuxt.config.js
const bodyParser = require('body-parser');
module.exports = {
serverMiddleware: [
'coexist-parser-proxy', // Needs to be before bodyParser
bodyParser.json()
],
proxy: {
'/api': 'some url',
}
}
This works for me, thx.
For future: is there a pathway to not have this workaround dependency?
const bodyParser = require('body-parser');
module.exports = {
serverMiddleware: [
'coexist-parser-proxy', // Needs to be before bodyParser
bodyParser.json()
],
proxy: {
'/api': 'some url',
}
}
Any updates on this? Are you guys still using this workaround?