-
Notifications
You must be signed in to change notification settings - Fork 7
/
server.js
46 lines (37 loc) · 1.06 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
var bodyParser = require('body-parser');
var express = require('express');
var fakeUsers = require('./server/fake-users');
var app = express();
var TIMEOUT = 1000;
// Serve all the angular files under testapp
app.use(
express.static(__dirname + '/testapp'),
express.static(__dirname));
app.use(bodyParser.json());
var start = function() {
var persistentUsers = fakeUsers.getUsers();
app.get('/users', function(req, res) {
setTimeout(function() {
res.send({list: fakeUsers.getUsers()});
}, TIMEOUT);
});
app.get('/persistent/list', function(req, res) {
setTimeout(function() {
res.send({list: persistentUsers});
}, TIMEOUT);
});
app.post('/persistent/add', function(req, res) {
setTimeout(function() {
if (!req.body || !req.body.user) {
res.sendStatus(400);
}
persistentUsers.push(req.body.user);
res.sendStatus(200);
}, TIMEOUT);
});
var server = app.listen(9000, function() {
console.log('App listening at http://localhost:%s',
server.address().port);
});
};
start();