Skip to content

Instantly share code, notes, and snippets.

@fraserxu
Last active February 6, 2018 09:51
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save fraserxu/685bf6c59fe4972f052d to your computer and use it in GitHub Desktop.
Save fraserxu/685bf6c59fe4972f052d to your computer and use it in GitHub Desktop.
Handling CORS in Meteor app
/*
* packages/reststop2/auth.js
* Add a method to handle OPTIONS request
*/
// return nothing
RESTstop.add('login', {'method': 'OPTIONS'}, function() {})
/*
* packages/reststop2/server.js
* line 142
*/
WebApp.connectHandlers.use(function(req, res, next) {
// add allow origin
res.setHeader('Access-Control-Allow-Origin', '*');
// add headers
res.setHeader('Access-Control-Allow-Headers', [
'Accept',
'Accept-Charset',
'Accept-Encoding',
'Accept-Language',
'Accept-Datetime',
'Authorization',
'Cache-Control',
'Connection',
'Cookie',
'Content-Length',
'Content-MD5',
'Content-Type',
'Date',
'User-Agent',
'X-Requested-With',
'Origin'
].join(', '));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment