0

While reading some tutorial I found that

app.use(function(req, res, next) {
   res.header("Access-Control-Allow-Origin", "*");
   res.header('Access-Control-Allow-Methods', 'DELETE, PUT');
   res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
   next();
});

What does every res.header mean? and what are their functions?

Aditya
  • 2,358
  • 6
  • 35
  • 61

1 Answers1

1

These headers allow cross-domain access: https://ru.wikipedia.org/wiki/Cross-origin_resource_sharing

Without these headers client scripts are allowed to get data from your server (edited: in your case you specify request types DELETE and PUT) only if their origin is the same (i.e. your client-side html and javascript are loaded from the same domain name). Scripts from different domains will receive an error like 'this origin is not allowed' or something like that.

Egor Stambakio
  • 17,836
  • 5
  • 33
  • 35