I have a React frontend that uses jwt to authenticate with the Django backend. The backend works and is connecting just fine using django views, but when I try to proxy a r
The correct answer will be to use manual proxy with
django:4000
localhost:8000
because if Django uses reverse
function which returns absolute url
reverse('preview-mail', args=[mail.pk],request=request)
you need to have correct HOST header for it, or you may get the result URL like https://django:4000/your-url`
const proxy = require('http-proxy-middleware');
module.exports = function(app) {
app.use(
proxy('/api', {
target: 'http://django:4000',
changeOrigin: true,
secure: false,
pathRewrite: {
'^/api': ''
},
onProxyReq: function (proxyReq, req, res) {
proxyReq.setHeader("host", 'localhost:8000')
}
})
)
}