Skip to content

Instantly share code, notes, and snippets.

@agreen757
Created April 16, 2015 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agreen757/0fb00deb4b379219afea to your computer and use it in GitHub Desktop.
Save agreen757/0fb00deb4b379219afea to your computer and use it in GitHub Desktop.
Using the CORS module of node for dynamic origins
var cors = require('cors')
var whitelist = ['http://localhost:4000','http://someotherserver.com'];
var corsOptions = {
origin: function(origin, callback){
var originIsWhitelisted = whitelist.indexOf(origin) !== -1;
callback(null, originIsWhitelisted);
}
};
app.options('/chans',cors(corsOptions))
app.put('/chans',cors(),function(req,resp){
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment