前提・実現したいこと
API Gateway, Lambda, Node.jsを使用してサーバーレス環境を構築しております。
初訪問者にはランダムに生成したCookieを付与し、Cookieを既に持っているユーザーからは、
そのCookieを取得し、URLにパラメータとして組み込みたいと考えています。
MethodはGetです。
発生している問題・エラーメッセージ
Cookieの付与はできているのですが、
Cookieを既に持っているユーザーから取得することができず、
Cookie取得先の指定方法を知りたいです。
myCookie=undefined
該当のソースコード
Node.js
1'use strict'; 2exports.handler = function(event, context) { 3 console.log("{'Cookie':event['Cookie']}"); 4 var date = new Date(); 5 6 date.setTime(+ date + (365 * 86400000)); //24 * 60 * 60 * 100 7 8 9 var registeredCookieValue = event['Cookie']; 10 var cookieVal; 11 12 if (registeredCookieValue != '') { 13 cookieVal = registeredCookieValue; 14 } else{ 15 cookieVal = Math.random().toString(36).substring(7); // Generate a random cookie string 16 } 17 18 var cookieString = "myCookie="+cookieVal+"; domain=l54ibjsrug.execute-api.us-east-2.amazonaws.com; expires="+date.toGMTString()+";"; 19 20 context.done(null, 21 {Cookie: cookieString , 22 statusCode: 302, 23 Location : "https://questant.jp/q/JU41D17S?session_id=" + cookieVal} 24 ); 25 26};
試したこと
Cookie取得の方法として、Lambda上で指定先を
event['Cookie']と試してみましたが、うまくいきませんでした。
メソッドリクエストのHTTPヘッダー:Cokkie
統合リクエストのHTTpヘッダー:Cookie
統合リクエストのマッピング元:method.request.header.Cookie
あなたの回答
tips
プレビュー