-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
107 lines (91 loc) · 2.33 KB
/
app.js
File metadata and controls
107 lines (91 loc) · 2.33 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
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
98
99
100
101
102
103
104
105
106
107
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
app.locals.pretty = true;
/**
* template engine
*/
app.set('view engine', 'pug');
app.set('views', './views');
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: false }))
app.get('/form_receiver', (req, resp) => {
var title = req.query.title;
var description = req.query.description;
resp.send(`title: ${title}<br>
description: ${description}`);
});
app.get('/form', (req, resp) => {
resp.render('form');
});
app.post('/form_receiver', (req, resp) => {
var title = req.body.title;
var description = req.body.description;
resp.send(`title: ${title}<br>
description: ${description}`);
});
app.get('/form', (req, resp) => {
resp.render('form');
});
app.get(['/topic/:id', '/topic'], (req, resp) => {
// resp.send(req.query);
var content = [
'Javscript is...',
'Nodsjs is...',
'Express is...'
];
// resp.render('topic', {
// id : req.query.id,
// content: req.query.id < 3 ? content[req.query.id] : content[0],
// arr: content
// });
var output = ``;
for (var i = 0; i < content.length; i++) {
output += `<a href='/topic/${i}'>${content[i]}</a><br>`;
}
if (req.params.id) {
output += `<br>${content[req.params.id]}`;
}
resp.send(output);
});
app.get('/topic/:id/:mode', (req, resp) => {
resp.send(req.params.id + ', ' + req.params.mode);
});
app.get('/template', function(req, resp) {
resp.render('temp', {
'_time': new Date().toString(),
'_title': 'Test pug'
});
});
app.get('/', (req, resp) => {
resp.send('Hello home page');
});
app.get('/dynamic', (req, resp) => {
var lis = '';
for (var i = 0; i < 5; i++) {
lis += `<li>coding</li>`
}
var output = `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>inner/static</title>
</head>
<body>
<h1>Hello Dynamic.</h1>
<ol>
${lis}
</ol>
</body>
</html>`;
resp.send(output);
});
app.get('/route', (req, resp) => {
resp.send('Hello router, <img src="/profile_picture.png" />')
});
app.get('/login', (req, resp) => {
resp.send('<h1>Login please</h1>');
});
app.listen(3000, () => {
console.log('Connected 3000 port!');
});