Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set HTTP Options Response w/ Claudia-Api-Builder for AWS ApiGateway

I am trying to set the Access-Control-Allow-Methods header for options and it appears currently that claudia-api-builder does not have the ability to set the http options response, like a GET request would. See GET example below.

GET Example

api.get('/hard-coded-headers', function () {
   return 'OK';
}, {success: {headers: {'Access-Control-Allow-Methods': 'GET, HEAD, OPTIONS'}}});

Furthermore ...

If this header value is set via aws-api-gateway -> resources -> OPTIONS > Integration Response and then if you were to perform a claudia update it would be overwritten back to its default state as seen below.

AWS-ApiGateway Custom mapping response setting

The claudia-api-builder docs show that it supports API Gateway custom error responses but nothing for success.

I would like to be able to set options custom header responses like the way a GET request is handled. Is this possible?

like image 570
Tyler Rafferty Avatar asked Jan 03 '18 17:01

Tyler Rafferty


1 Answers

Have you tried the new ApiResponse() function?

api.get('/programmatic-headers', function () {
  return new api.ApiResponse('OK', {'Access-Control-Allow-Methods': 'GET, HEAD, OPTIONS'}, 200);
});
like image 51
RickyM Avatar answered Oct 22 '22 12:10

RickyM