I'm attempting to GET information from a site using $http, and I've honestly looked all over and tried tons of different things but I'm not sure exactly how to set the headers for 'Access-Control-Allow-Origin'. I'm not sure if I'm just misunderstanding completely or something, but any help is really appreciated, thanks a ton in advance!
XMLHttpRequest cannot load http://nhlwc.cdnak.neulion.com/fs1/nhl/league/teamroster/NJD/iphone/clubroster.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 503.
Here is my code:
relavant code from rosterService:
(function(){
'use strict';
var URL = 'http://nhlwc.cdnak.neulion.com/fs1/nhl/league/teamroster/NJD/iphone/clubroster.json';
angular
.module("DevilsFanApp")
.factory("RosterService", RosterService);
function RosterService($rootScope, $http) {
function fetchPlayers(callback){
return $http({
method: 'GET',
url: URL,
dataType: 'jsonp'
});
}
}
})();
server.js:
var express = require('express');
var app = express();
var ipaddress = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1';
var port = process.env.OPENSHIFT_NODEJS_PORT || 3000;
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "http://localhost:3000"); // instead of * give a try with
res.header('Access-Control-Allow-Methods', 'OPTIONS,GET,POST,PUT,DELETE');
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.use(express.static(__dirname + '/public'));
app.listen(port, ipaddress);
config.js:
(function(){
angular
.module("DevilsFanApp")
.config(Configure);
function Configure($routeProvider,$httpProvider) {
$routeProvider
.when("/roster",{
templateUrl: "./views/roster/roster.view.html",
controller: "RosterController"
})
.otherwise({
redirectTo: "/home"
});
}
})();