Page 225 - Nodejs 교과서 개정2판
P. 225
ਬೞҊ रݶ req ёী ؘఠܳ ֍যفݶ ؾפ
app.use((req, res, next) => {
req.data = '데이터 넣기';
next();
}, (req, res, next) => {
console.log(req.data); // 데이터 받기
next();
});
അ ਃ ܻغח زউ req.dataܳ ా೧ ٜਝয рী ؘఠܳ ҕਬೡ ࣻ णפ ࢜۽ ਃ য়ݶ r
eq.dataח ୡӝചؾפ ࣘࢿݺ ԙ dataੌ ਃח হ݅ ܲ ٜਝয৬ Ҁ ঋѱ ઑब೧ঠ פ
ܳ ٜয ࣘࢿݺਸ body۽ ೠݶ SFR CPEZ CPEZ QBSTFS ٜਝয৬ ӝמ Ҁѱ ؾפ
/PUF BQQ TFUҗ ର
app.setਵ۽ झۨझীࢲ ؘఠܳ ೡ ࣻ ח Ѫਸ ߓਛणפ app.get ژח req.app.getਵ۽ য٣ࢲٚ ؘ
ఠܳ оઉৢ ࣻ णפ ೞ݅ app.setਸ ࢎਊೞ ঋҊ req ёী ؘఠܳ ֍যࢲ ٜਝয۽ ׳ೞח ਬо
णפ app.set झۨझীࢲ ਵ۽ ࢎਊغ۽ ࢎਊ ѐѐੋ чਸ ֍ӝীח ࠗೞݴ জ ࢸਸ ҕ
ਬೡ ٸ ࢎਊೞݶ ؾפ
req ёח ਃਸ ࠁմ ࢎਊ ѐѐੋীѱ ӈࣘغ۽ req ёܳ ా೧ ѐੋ ؘఠܳ ׳ೞח Ѫ જणפ
ٜਝযܳ ࢎਊೡ ٸ ਬਊೠ ಁఢ ೠ оܳ ࣗѐפ ٜਝয উী ٜਝযܳ ֍ח ߑधੑפ
ઁ ف ߑध э ӝמਸ פ
app.use(morgan('dev'));
// 또는
app.use((req, res, next) => {
morgan('dev')(req, res, next);
});
ಁఢ ਬਊೠ ਬח ӝઓ ٜਝয ӝמਸ ഛೡ ࣻ ӝ ٸޙੑפ ܳ ٜয җ э ࠙ӝ ܻ
ܳ ೡ ࣻب णפ ઑѤޙী ٮۄ ܲ ٜਝযܳ ਊೞח ٘ੑפ
app.use((req, res, next) => {
if (process.env.NODE_ENV === 'production') {
morgan('combined')(req, res, next);