I want to custom response with Cloudfront function. Here is my Cloudfront function. I’m wondering that “fetch” will work in Cloudfront function. If it doesn’t wwork is there any way for me to get the same result as the code below
async function handler(event) {
const request = event.request;
const response = await fetch('https://url');
// Modify the response headers
const headers = response.headers;
headers.set('Access-Control-Allow-Origin', request.headers.get('origin'));
headers.set('Cache-Control', 'public, max-age=60');
// Read the response body as text
const text = await response.text();
// Modify the response body
const body = text.replace('https://url', request.headers.host);
// Return the modified response
return {
status: response.status,
statusDescription: response.statusText,
headers: headers,
body: body
};
}