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:

enter image description here

okay thats abit hard read here 2 errors:

  1. failed load resource: origin http://angular.mydomain.com not allowed access-control-allow-origin
  2. xmlhttprequest cannot load http://angular.mydomain.com:8080/login. origin http://angular.mydomain.com not allowed access-control-allow_origin.

can tell me whats going on here??

headers

enter image description here

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

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -