user288093 user288093 - 6 months ago 61
Node.js Question

write a reverse proxy in node js to call the api in django

My frontend code is running in angular at node httpserver port
My backend services runnning in python django framework at port
While calling my backend servies from angular http methods throws cors exception
so i wrote a proxy controller in my node js

var http = require('http'),
httpProxy = require('http-proxy');

var proxy = httpProxy.createProxyServer();

http.createServer(function (req, res) {
// This simulates an operation that takes 500ms to execute
setTimeout(function () {
proxy.web(req, res, {
target: ''
}, 500);
}).listen(8080, "");

to listen and bind at angular. i run as the node proxycontroller.js, results a another port no

from proxy controller it calls my backend service and result json but from the angular js calling the proxy controller from the http.get() method results cors problem

please help to solve this problem.


Enable CORS in Django

Uses this third-party lib django-cors to do it.

You are getting CORS because you are making the call from your AngularJS app and its host is, different from your Django app host