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

}
           		e.target.username.value	=	'';
           });



          about.html

           <!DOCTYPE	html>
           <html>
           <head>
           		<meta	charset="utf-8"	/>
           		<title>RESTful	SERVER</title>
           		<link	rel="stylesheet"	href="./restFront.css"	/>
           </head>
           <body>
           <nav>
           		<a	href="/">Home</a>
           		<a	href="/about">About</a>
           </nav>
           <div>
           		<h2>소개	페이지입니다.</h2>
           		<p>사용자	이름을	등록하세요!</p>
           </div>
           </body>
           </html>




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


           http.createServer(async	(req,	res)	=>	{
           		try	{
           				console.log(req.method,	req.url);
           				if	(req.method	===	'GET')	{
           						if	(req.url	===	'/')	{
           								const	data	=	await	fs.readFile('./restFront.html');
           								res.writeHead(200,	{	'Content-Type':	'text/html;	charset=utf-8'	});
           								return	res.end(data);
           						}	else	if	(req.url	===	'/about')	{
           								const	data	=	await	fs.readFile('./about.html');
           								res.writeHead(200,	{	'Content-Type':	'text/html;	charset=utf-8'	})
           								return	res.end(data);
           						}
           						//	주소가	/도	/about도	아니면
   159   160   161   162   163   164   165   166   167   168   169