http://localhost:3030/cookie 처럼,
cookie directory 안의 page에 만들어 보겠다!
현재는..
// 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",
< 코드 >
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",
],
});
response.end("Cookie!!");
})
.listen(3030);
"Domain=Domain; Domain=o2.org",
// 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",
// "Domain=Domain; Domain=o2.org",
// ],
// });
Conclusion
path: 어느 path에서 동작 할 것인가를 제한.
domain : 어떤 domain에서 동작 할 것인가를 제한.