javascript - node headers are set however some users experiences Access-control errors -
i have node server runs following header code:
app.all('/*', function (req, res, next) { // cors headers res.header("access-control-allow-origin", "*"); // restrict required domain res.header('access-control-allow-methods', 'get,put,post,delete,options'); // set custom headers cors res.header('access-control-allow-headers', 'content-type,accept,x-access-token,x-key'); if (req.method == 'options') { res.status(200).end(); } else { next(); } }); now on many computers , browsers works fine (including own) not sitting @ office gets following error message:

okay thats abit hard read here 2 errors:
- failed load resource: origin
http://angular.mydomain.comnot allowed access-control-allow-origin - xmlhttprequest cannot load
http://angular.mydomain.com:8080/login. originhttp://angular.mydomain.comnot allowed access-control-allow_origin.
can tell me whats going on here??
headers

the login route:
router.route('/login') .post(function (req, res) { var user = user.build(); var username = req.body.username || ''; var password = req.body.password || ''; if (username == '' || password == '') { res.status(401); res.json({ "status": 401, "message": "invalid credentials" }); return; } var salt = bcrypt.gensaltsync(10); var hash = bcrypt.hashsync(password, salt); user.retrievebynamepassword(username, function (users) { var = 0; if (bcrypt.comparesync(password, users.password)) { var log = user_login.build() log.findlastlogin(users.id, function (result) { users.last_login = result; if (users.user_type_id > 3) { res.json(gentoken(users, null)); } else { var div = division.build(); selected_user = users; var root = [selected_user.division_id]; div.retrievebydivisionid(selected_user.division_id, function (division) { var result = []; var root = [division]; (function loop() { var element = root[0]; var divisions = division.build(); divisions.retrievebyparentid(element.id, function (divisions) { if (divisions) { divisions.foreach(function (division) { root.push(division); }); result.push(element.id); root.splice(0, 1); if (root.length > 0) { loop() } else if (root.length == 0) { res.json(gentoken(users, result)); } } else { res.send(401, "no division found"); } }); }()); }) } }, function (error) { var = 0; }); } else { // if authentication fails, send 401 res.status(401); res.json({ "status": 401, "message": "invalid credentials" }); return; } }, function (error) { res.status(401); res.json({ "status": 401, "message": "invalid credentials" }); return; }); });
maybe receiving 404 or similar code represents unreachable resource foreign network.
Comments
Post a Comment