Page 172 - Nodejs 교과서 개정2판
P. 172
const http = require('http');
http.createServer((req, res) => {
console.log(req.url, req.headers.cookie);
res.writeHead(200, { 'Set-Cookie': 'mycookie=test' });
res.end('Hello Cookie');
})
.listen(8083, () => {
console.log('8083번 포트에서 서버 대기 중입니다!');
});
콘솔
$ node cookie
8083번 포트에서 서버 대기 중입니다!
ఃח name=zerocho;year=1994ۢ ޙৌ ഋधਵ۽ ઓפ ః рীח ࣁۿਵ۽ ҳ࠙ؾפ
createServer ݫࢲ٘ ߔীࢲח req ёী ѹ ח ఃܳ оઉ২פ ఃח req.headers.DPPLJFী
ٜয णפ req.headersח ਃ ؊ܳ פ ઑӘ ী ఃח ਃҗ ؊ܳ ా೧ য়р
Ҋ ঠӝ೮ਃ
؊ী ఃܳ ӝ۾೧ঠ ೞ۽ res.writeHead ݫࢲ٘ܳ ࢎਊ೮णפ Set-Cookieח ࠳ۄೠప
җ э ч ఃܳ ೞۄח ੑפ पઁ۽ ਸ ߉ ࠳ۄח mycookie=testۄח ఃܳ
פ
MPDBMIPTU ী ࣘפ req.urlҗ req.headers.cookieী ೠ ࠁܳ ۽Ӧೞب۾ ೮णפ req.url
ࣗ path৬ search ࠗ࠙ਸ ঌ݀פ
ചݶীח )FMMP $PPLJFо ڰҊ ࣛীࢲח җ э ݫदܳ ࠅ ࣻ णפ
콘솔
/ undefined
/favicon.ico { mycookie: 'test' }
݅ড प೯ Ѿҗо ਤ৬ ܰݶ ࠳ۄ ఃܳ ݽف ઁѢೠ റী द प೯೧ঠ פ ܲ ࢎա
۽Ӓ۔ ܻ ఃܳ ֍যفਸ ࣻب ӝ ٸޙੑפ
ਃ ࠙ݺ ೠ ߣ݅ ࠁչחؘ ف ѐо ӝ۾غয णפ GBWJDPO JDPח ਃೠ হחؘ ݈ભ ߣ૩
ਃ /)ীࢲח ఃী ೠ ࠁо হҊ աয়ݴ ف ߣ૩ ਃ(/favicon.ico)ীࢲח { mycookie test' }о
ӝ۾غणפ