forked from sandbox-team/techtalk-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
104 lines (91 loc) · 2.07 KB
/
server.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
98
99
100
101
102
103
104
require('colors');
var express = require('express'),
app = express(),
path = require('path');
app
.disable('x-powered-by')
.engine('html', require('ejs').renderFile)
.set('view engine', 'html')
.set('port', process.env.PORT || 3001)
.set('views', __dirname + '/views')
.use(express.favicon())
.use(express.logger('tiny'))
.use(express.static(path.join(__dirname, 'public')))
.use(express.bodyParser())
.use(express.methodOverride())
.use(express.cookieParser())
.use(app.router);
app.get('/', function(req, res){
res.render('index');
});
//stub routes
app.get('/views/:templateName', function(req, res) {
console.log('view changed to: ' + req.params.templateName.green);
res.render(req.params.templateName);
});
app.get('/test', function(req, res) {
res.send({
'3': [{
id: '1',
title: 'CSS features',
location: 'k1-3 215',
author: {
id: 'tester',
firstName: 'Sergey',
lastName: 'Net ne on'
}
}],
'21': [{
id: '2',
title: 'CSS55 features',
location: 'k1',
author: {
id: 'tester',
firstName: 'Sergey',
lastName: 'Net ne on'
}
}, {
id: '1',
title: 'JS',
location: 'n58',
author: {
id: 'tester',
firstName: 'Sergey',
lastName: 'Net ne on'
}
}]
});
});
app.get('/details/:techtalkId', function(req, res) {
var data = {
'1': {
title: 'CSS features',
content: '<b>html here</b>'
},
'2': {
title: 'CSS2 features',
content: '<i>html here</i>'
}
};
var id = req.params.techtalkId;
res.send(data[id] || {});
});
app.post('/auth', function(req, res) {
console.log(req.body.green);
var login = req.body.login,
password = req.body.password;
if (login === 'test' && password === '123') {
res.send({
status: 'success'
});
}
else {
res.send({
status: 'error',
message: 'Not valid login or password'
})
}
})
//server starts here
app.listen(3000);
console.log('start web-server on port 3000'.green);