Skip to content

Instantly share code, notes, and snippets.

@dev0x10
Last active September 7, 2016 03:27
Show Gist options
  • Save dev0x10/0277732baa91904696cbee6181a62497 to your computer and use it in GitHub Desktop.
Save dev0x10/0277732baa91904696cbee6181a62497 to your computer and use it in GitHub Desktop.
HapiJS CORS Handler For 'DELETE'
if (request.method === 'options') {
let response = request.response.isBoom ? request.response.output : request.response;
response.statusCode = 200;
response.headers['access-control-expose-headers'] = 'content-type, content-length, etag';
response.headers['access-control-max-age'] = 60 * 10; // might be not needed
// dynamically set allowed headers & method (this is the important part)
if (request.headers['access-control-request-headers']) {
response.headers['access-control-allow-headers'] = request.headers['access-control-request-headers']
}
if (request.headers['access-control-request-method']) {
response.headers['access-control-allow-methods'] = request.headers['access-control-request-method'];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment