Page 165 - Nodejs 교과서 개정2판
P. 165

try	{
           								const	data	=	await	fs.readFile(`.${req.url}`);
           								return	res.end(data);
           						}	catch	(err)	{
           								//	주소에	해당하는	라우트를	못	찾았다는	404	Not	Found	error	발생
           						}
           				}
           				res.writeHead(404);
           				return	res.end('NOT	FOUND');
           		}	catch	(err)	{
           				console.error(err);
           				res.writeHead(500,	{	'Content-Type':	'text/plain;	charset=utf-8'	});
           				res.end(err.message);
           		}
           })
           		.listen(8082,	()	=>	{
           				console.log('8082번	포트에서	서버	대기	중입니다');
           		});




         SFTU4FSWFS KTо ೨बੑפ׮  ௏٘ܳ ࠁݶ req.NFUIPE۽ )551 ਃ୒ ݫࢲ٘ܳ ҳ࠙ೞҊ ੓णפ׮  ݫࢲ٘о G

         ET੉ݶ ׮द req.url۽ ਃ୒ ઱ࣗܳ ҳ࠙೤פ׮  ઱ࣗо  ੌ ٸח SFTU'SPOU IUNMਸ ઁҕೞҊ  ઱ࣗо  BCPVU
         ੉ݶ BCPVU IUNM ౵ੌਸ ઁҕ೤פ׮  ੉৻੄ ҃਋ীח ઱ࣗী ੸൦ ౵ੌਸ ઁҕ೤פ׮   SFTU'SPOU KTۄݶ SFTU
         'SPOU KT ౵ੌਸ ઁҕೡ Ѫ੉Ҋ   SFTU'SPOU DTTۄݶ SFTU'SPOU DTT ౵ੌਸ ઁҕೡ Ѫੑפ׮  ݅ড ઓ੤ೞ૑ ঋח

         ౵ੌਸ ਃ୒೮Ѣա GET ݫࢲ٘ ਃ୒੉ ইצ ҃਋ۄݶ     /05 '06/% ী۞о ਽׹ਵ۽ ੹࣠ؾפ׮  ਽׹ җ

         ੿ ઺ী ৘ӝ஖ ޅೠ ী۞о ߊࢤೠ ҃਋ীח     ী۞о ਽׹ਵ۽ ੹࣠ؾפ׮ पޖীࢲ    ਸ ੹࣠ೞח ҃਋
         ח ٘ޟפ׮



           /PUF ™ SFT FOE খী SFUVSO਷ ৵ ࠢ੉աਃ

           ੑޙ੗ٜ੉ ݆੉ ೞח ଱п ઺ ೞաח res.endܳ ഐ୹ೞݶ ೣࣻо ઙܐػ׮ח Ѫੑפ׮  ֢٘ب ੌ߈੸ੋ ੗߄झ௼݀౟ ޙߨ
           ਸ ٮܰ޲۽ returnਸ ࠢ੉૑ ঋח ೠ ೣࣻо ઙܐغ૑ ঋणפ׮  ٮۄࢲ ׮਺ী ௏٘о ੉য૑ח ҃਋ীח returnਸ ॄࢲ ݺ

           द੸ਵ۽ ೣࣻܳ ઙܐ೮णפ׮  returnਸ ࠢ੉૑ ঋইࢲ res.end э਷ ݫࢲ٘о ৈ۞ ߣ प೯ػ׮ݶ &SSPS  $BO U TFU IFBE
           FST BGUFS UIFZ BSF TFOU UP UIF DMJFOU  ী۞о ߊࢤ೤פ׮




         SFTU4FSWFS KT੄ աݠ૑ ࠗ࠙ਸ ৮ࢿೞৈ ೐۽Ӓ۔ਸ ৮ࢿೞѷणפ׮

          restServer.js

           const	http	=	require('http');
           const	fs	=	require('fs').promises;


           const	users	=	{};	//	데이터	저장용
   160   161   162   163   164   165   166   167   168   169   170