angularjs - Angular: 'Access-Control-Allow-Origin' header is present on the requested resource -
i've read alot of same or similar questions , answers configure server. client app angular.js
"ionic"
server app node.js
, deployed on heroku
. here server configuration:
// set cors resource sharing app.use(function(req, res, next){ res.header('access-control-allow-origin', '*'); res.header('access-control-allow-methods', 'get,put,post,delete'); res.header('access-control-allow-headers', 'content-type, authorization'); res.header('access-control-allow-credentials', true); next(); })
note: client communicate server when run server locally
my client app fail make http request , getting error:
xmlhttprequest cannot load https://myheroku.herokuapp.com/api/x. no 'access-control-allow-origin' header present on requested resource. origin 'http://localhost:8100' therefore not allowed access. response had http status code 503.
here request header:
accept:*/* accept-encoding:gzip, deflate, sdch accept-language:en-us,en;q=0.8,ar;q=0.6,fi;q=0.4,it;q=0.2,en-gb;q=0.2,en-ca;q=0.2 access-control-request-headers:accept, authorization access-control-request-method:get connection:keep-alive host:myheroku.herokuapp.com origin:http://localhost:8100 referer:http://localhost:8100/
am sorry if it's silly mistake maybe useful beginners me. checked server app logs heroku logs
, found
heroku process failed bind $port within 60 seconds of launch
and since heroku assign port app how fixed issue: from:
var server = app.listen(3000, function(){ console.log('app listeining on', server.address().port); })
to:
var server = app.listen(process.env.port || 5000, function(){ console.log('app listeining on', server.address().port); })
Comments
Post a Comment