Last active
September 7, 2016 03:27
-
-
Save dev0x10/0277732baa91904696cbee6181a62497 to your computer and use it in GitHub Desktop.
HapiJS CORS Handler For 'DELETE'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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