將原始伺服器標頭新增至 CloudFront Functions 檢視器請求事件 - AWS SDK 程式碼範例

AWS文件開發套件範例 GitHub 儲存庫中有更多可用的 AWS SDK 範例。

將原始伺服器標頭新增至 CloudFront Functions 檢視器請求事件

下列程式碼範例示範如何將原始伺服器標頭新增至 CloudFront Functions 檢視器請求事件。

JavaScript
適用於 CloudFront Functions 的 JavaScript 執行時期 2.0
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 CloudFront Functions 範例儲存庫中設定和執行。

async 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; }