I have created a web application in AngularJS and a Flask server up and running on localhost:5000/
. I wanted to make a login service, so I included the following code in my controller in AngularJS:
$scope.login = function() {
$http({
method: 'POST',
data: {
username: $scope.username,
password: $scope.password
},
url: 'http://127.0.0.1:5000/login/'
}).then(function successCallback(response) {
console.log('successCallback')
}, function errorCallback(response) {
console.log('errorCallback')
});
}
I call the login()
method from the UI. But this gives me the following error:
XMLHttpRequest cannot load http://127.0.0.1:5000/login/. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
Further when I researched on this error, I found this link, which states that my page is on a different domain than my server. How do I bring my AngularJS and python server on same domain? What piece of code will I have to specify so that in place of url:'http://127.0.0.1:5000/login/'
, I just have to specify '/login'
? I know this might be trivial question, but please guide me.