Setting HTTP response parameters with Claudia-Api-Builder for AWS ApiGateway

I am trying to set the Access-Control-Allow-Methods header for options , and currently it shows that claudia-api-builder is not able to set the http parameters response, like a GET request. See the GET example below.

GET example

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

Further...

If this header value is set via aws-api-gateway -> resources -> OPTIONS > Integration Response , and then if you need to perform claudia update , it will be overwritten to the default state, as shown below.

AWS-ApiGateway Customizing a Mapping Response

The claudia-api-builder show that it supports custom Gateway API error responses, but it fails.

I would like to be able to customize the responses of custom headers, for example, how the GET request is processed. Is it possible?

+8
aws-lambda aws-api-gateway claudiajs
source share
2 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); }); 
+2
source

Resource Sharing (CORS) is a mechanism that uses additional HTTP headers to allow a user agent to access selected resources from a server in a different source (domain) than the site currently in use.

you can guarantee permission to a domain (or several), http-verb or contentType

 res.header('Access-Control-Allow-Origin', 'example.com'); res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE'); res.header('Access-Control-Allow-Headers', 'Content-Type'); 
+1
source

All Articles