Skip to content

Instantly share code, notes, and snippets.

@ghostbar
Last active December 23, 2015 05:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ghostbar/6586390 to your computer and use it in GitHub Desktop.
Save ghostbar/6586390 to your computer and use it in GitHub Desktop.
function unkMH(req, res) {
var allowHeaders;
if (req.method.toLowerCase() === 'options') {
allowHeaders = ['Accept', 'Accept-Version', 'Content-Type', 'Api-Version', 'Authorization'];
if (res.methods.indexOf('OPTIONS') === -1) {
res.methods.push('OPTIONS');
}
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Headers', allowHeaders.join(', '));
res.header('Access-Control-Allow-Methods', res.methods.join(', '));
res.header('Access-Control-Allow-Origin', req.headers.origin);
return res.send(204);
} else {
return res.send(new restify.MethodNotAllowedError());
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment