-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
97 lines (84 loc) · 2.25 KB
/
app.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
var express = require('express');//express 모듈을 로드
var app = express();//express 모듈의 리턴값을 app에 저장하고 사용
app.set('view engine', 'jade');//view engine, 사용할 템플리트 엔진
app.set('views', './views');//views, 템플리트가 있는 디렉토리
app.locals.pretty = true // jade 코드 자동 정렬
var bodyParser = require('body-parser');//body-parser모듈
app.use(bodyParser.urlencoded({ extended: false }));// parse application/x-www-form-urlencoded
app.use(express.static('public'));
app.get('/form', function(req, res){
res.render('form');
});
app.post('/form_receiver', function(req, res){
var title = req.body.title;
var description = req.body.description;
res.send(title+', '+description);
});
app.get('/queryURL3/:id/:mode', function(req, res){
res.send(req.params.id +', '+ req.params.mode);
});
app.get('/queryURL2/:id', function(req, res){
var arrLink = [
'apple',
'baby',
'car'
];
var output = `
<a href="/queryURL2/0">apple</a><br>
<a href="/queryURL2/1">baby</a><br>
<a href="/queryURL2/2">car</a><br>
${arrLink[req.params.id]}
`
res.send(output);
});
app.get('/queryURL', function(req, res){
var arrLink = [
'apple',
'baby',
'car'
];
var output = `
<a href="/queryURL?id=0">apple</a><br>
<a href="/queryURL?id=1">baby</a><br>
<a href="/queryURL?id=2">car</a><br>
${arrLink[req.query.id]}
`
res.send(output);
});
app.get('/template', function(req, res){
res.render('temp', {time:Date(), _title:'Jade'});//temp.jade 템플렛 렌더링
});
app.get('/dynamic', function(req, res){
var lis ='';
for(var i =0; i<5; i++){
lis = lis + '<li>coding</li>';
}
var time = Date();
var output = `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
Hello Dynamic!
${lis}
</br>
${time}
</body>
</html>`;
res.send(output);
})
app.get('/', function(req, res){//get이 라우터의 역할
res.send('hello worls');
});
app.get('/login', function(req,res){
res.send('login please');
});
app.get('/logo', function(req, res){
res.send('hello logo, <img src="./logo.PNG">');
});
app.listen(3000, function(){
console.log('conneted 3000 port');
});