base.js
1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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);