-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathserver.js
77 lines (67 loc) · 1.75 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
var express = require('express');
var bodyParser = require('body-parser');
var _ = require('underscore');
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.text({type: 'text/plain'}));
app.use(express.static('public'));
app.use(require('connect-livereload')());
app.get('/', function (request, response) {
response.sendfile('public/index.html');
});
app.get('/api/sample', function (request, response) {
response.send({ name: "Ravi" });
});
var achievements = [
{
title: 'Received Microsoft MVP Award',
type: 'major',
from:'Microsoft'
},
{
title: 'Approved as SitePoint author',
type: 'major',
from:'SitePoint'
},
{
title: 'Approved as DotnetCurry author',
type: 'major',
from:'DotnetCurry'
},
{
title: 'Mention on ASP.NET',
type: 'medium',
from:'asp.net'
},
{
title: 'First article published on SitePoint',
type: 'minor',
from:'SitePoint'
},
{
title: 'Got a side project',
type: 'minor',
from:'Self'
},
{
title: 'Boss patted me for my work',
type: 'minor',
from:'Boss'
}
];
app.get('/api/achievements/:type', function (request, response) {
response.send(_.filter(achievements, function (a) {
return a.type === request.params.type;
}));
});
app.get('/api/achievements', function (request, response) {
response.send(achievements);
});
app.post('/api/achievements', function(request, response){
achievements.push(JSON.parse(request.body));
response.send(achievements);
});
app.listen(8000, function () {
console.log('Express server started!!!');
});