다른 페이지로 넘기는거
1.서버에서는 모든 페이지를 제공해줘야 함
2.url을 parse하여 다른페이지로 넘김
서버
var fs = require('fs');
var http = require('http');
var url = require('url');
http.createServer(function(request,response){
var pathname= url.parse(request.url).pathname;
if(pathname =='/')
{
fs.readFile('htmlpage.html',function(error,data){
response.writeHead(200, {'Content-Type':'text/html'});
response.end(data);
});
}
else if(pathname == '/video')
{
fs.readFile('committee.mp4',function (error,data){
response.writeHead(200, {'Content-Type':'video/mp4'});
response.end(data);
});
}
}).listen(59599,function(){
console.log('server is running');
});
클라이언트
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
</head>
<body>
<h1>Hello Node.js</h1>
<h2>Author.jongsoo-oh</h2>
<hr />
<p>emergency committee</p>
<video src="/video"width="600"height="400"controls autoplay loop></video>
</body>
</html>
'node.js' 카테고리의 다른 글
Sequelize와 mysql 연결 에러 (0) | 2019.08.05 |
---|