node.js - NodeJS , AngularJS not getting response when on different domain, getting success but without response data -
i developed application based on mean stack , works fine when ui , api on same domain-port. , when segregate ui , api , let deploying on different domain or local different port ,all api call successful no response data. fyi have access-control-allow-origin * , without behaviour same.
as in case of cross origin browser first sends option request. if in response of option request if access-control-allow-origin found sends actual request, else gives cros error.
you can add these lines of in app.js of nodejs code. solve purpose.
app.use(function(req, res, next) { res.setheader('access-control-allow-headers', 'origin, x-requested-with, content-type, accept'); res.setheader('access-control-allow-methods', 'post,head,get,put,delete,options'); res.setheader('access-control-allow-origin', '*'); next(); }); app.options('*', function(req, res, next) { res.send(); });
Comments
Post a Comment