수업소개
쿠키의 유효범위를 정의하는 path와 domain 옵션을 살펴봅시다.
강의
소스코드
nodejs/cookie.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | var http = require( 'http' ); var cookie = require( 'cookie' ); http.createServer( function (request, response){ console.log(request.headers.cookie); var cookies = {}; if (request.headers.cookie !== undefined){ cookies = cookie.parse(request.headers.cookie); } console.log(cookies.yummy_cookie); response.writeHead(200, { 'Set-Cookie' :[ 'yummy_cookie=choco' , 'tasty_cookie=strawberry' , `Permanent=cookies; Max-Age=${60*60*24*30}`, 'Secure=Secure; Secure' , 'HttpOnly=HttpOnly; HttpOnly' , 'Path=Path; Path=/cookie' , 'Doamin=Domain; Domain=test.o2.org' ] }); response.end( 'Cookie!!' ); }).listen(3000); |