I'm currently working on a project with Django and AngularJS 1 for the front-end. I'm also using Gulp for browser Sync features. The code snippet below shows how I set up the Gulp server to work alongside the Django server as a proxy.
gulp.task('browser-sync', function() {
browserSync.init({
proxy: "localhost:8000"
});
});
However, I've encountered a CORS issue. The error message I see is:
XMLHttpRequest cannot load http://localhost:8000/static/js/data.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
The data.json file mentioned is used for frontend data as I haven't built the backend yet.
Here's an example of how I'm fetching data from the JSON file using Angular's $HTTP service:
marksApp.factory('getSubjectsService', ['$http',function($http){
return {
getSubjectNames : function(stdNum){
return $http.get('http://localhost:8000/static/js/data.json')
.then(function(data){
return data.data;
});
}
};
}]);