Pallavi Anderson

data-driven and context-aware

CORS on Meteor

| Comments

Meteor’s webapp package exposes the underlying connect API through WebApp.connectHandlers which can be used (among other things) to customize HTTP headers and enable CORS in a Meteor application.

1
2
3
4
5
// Listen to incoming HTTP requests, can only be used on the server
WebApp.connectHandlers.use(function(req, res, next) {
  res.setHeader("Access-Control-Allow-Origin", "*");
  return next();
});

Use the optional path argument to call the handler only for paths that match a specified string.

1
2
3
4
5
// Listen to incoming HTTP requests, can only be used on the server
WebApp.connectHandlers.use("/public", function(req, res, next) {
  res.setHeader("Access-Control-Allow-Origin", "*");
  return next();
});

Comments