Add cross-origin resource sharing (CORS) header to the request
The following example function adds an Origin
HTTP header to the request
if the request doesn’t already contain this header. This header is part of cross-origin resource
sharing (CORS)Host
header. For more information, see Origin
This is a viewer request function.
function handler(event) { var request = event.request; var headers = request.headers; var host = request.headers.host.value; // If origin header is missing, set it equal to the host header. if (!headers.origin) headers.origin = {value:`https://${host}`}; return request; }