이의준

server app.js로 통합

Showing 1 changed file with 0 additions and 43 deletions
var http = require('http');
var fs = require('fs');
var url = require('url');
var app = http.createServer(function(request,response){
var _url = request.url;
var queryData = url.parse(_url, true).query;
if(_url == '/'){
_url = '/Index.html';
}
if(_url == '/favicon.ico'){
return response.writeHead(404);
}
response.writeHead(200);
console.log(queryData.busNum);
if (queryData.busNum != null){ // 버스번호를 요청했을때 타임테이블 페이지로 전환
var timetableHTML = `
<!doctype html>
<html>
<head>
<title>Time Table</title>
<meta charset="utf-8">
<style type="text/css">
a { text-decoration:none }
</style>
</head>
<body>
<h1><a href="Index.html"><p style="text-align:center;">BTT</p></a></h1>
<br>
<h2>${queryData.busNum} BUS Time Table</h2>
<p> Response from API server ... </p>
</body>
</html>
`;
response.end(timetableHTML);
}
else{ // 아니라면, url 따라감
response.end(fs.readFileSync(__dirname + _url));
}
});
app.listen(23023);
\ No newline at end of file