AWS Lambda how do I properly allow CORs?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


AWS Lambda how do I properly allow CORs?



I know this question gets asked a lot and I have looked through other questions/answers but I still can't get it to work.



I have read and followed: https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html



This is my lambda function:


let http = require('https')

exports.handler = (event, context, callback) => {

const STORE_HASH = '1234'
const PATH = `/stores/${STORE_HASH}/v3/catalog/products?limit=100`
const AUTH_TOKEN = '1234'
const AUTH_CLIENT = '1324'

let options = {
"method": "GET",
"hostname": "api.bigcommerce.com",
"port": null,
"path": PATH,
"headers": {
"x-auth-client": AUTH_CLIENT,
"x-auth-token": AUTH_TOKEN,
"content-type": "application/json",
"cache-control": "no-cache",
"Access-Control-Allow-Origin": "*"
}
};

http.get(options, (res) => {
console.log('RESPONSE HERE:', res)
let body = ''
res.on('data', (d) => {
body += d
})
res.on('end', () => {
context.succeed(JSON.parse(body))
})
res.on('error', (err) => {
context.fail("err: " + err.message)
})
})
}



I call the function through an API gateway and I use axios to hit the endpoint.



Would really appreciate the help. Thank you.









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived