-
Notifications
You must be signed in to change notification settings - Fork 1
/
service_db_server.js
71 lines (64 loc) · 1.64 KB
/
service_db_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
/**
* Created by Laurent_Barbier on 10/04/2015.
*/
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use('/', express.static('./'));
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
var user = {
first: 'Christopher',
last: 'Columbus',
username: 'cc1492',
title: 'Admiral',
home: 'Genoa'
};
var data = [];
function r(min, max) {
var n = Math.floor(Math.random() * (max - min + 1)) + min;
if (n < 10) {
return '0' + n;
}
else {
return n;
}
}
function p(start, end, total, current) {
return Math.floor((end - start) * (current / total)) + start;
}
function d(plusDays) {
var start = new Date(1492, 7, 3);
var current = new Date(1492, 7, 3);
current.setDate(start.getDate() + plusDays);
return current.toDateString();
}
function makeData() {
var t = 70;
for (var x = 0; x < t; x++) {
var entry = {
day: d(x),
time: r(0, 23) + ':' + r(0, 59),
longitude: p(37, 25, t, x) + '\u00B0' + r(0, 59) + ' N',
latitude: p(6, 77, t, x) + '\u00B0' + r(0, 59) + ' W'
};
data.push(entry);
}
}
makeData();
app.get('/get/user', function (req, res) {
res.json(user);
});
app.get('/get/data', function (req, res) {
res.json(data);
});
app.post('/set/user', function (req, res) {
console.log(req.body.userData);
user = req.body.userData;
res.json({data: user, status: "User updated."});
});
app.post('/set/data', function (req, res) {
data = req.body.data;
res.json({data: data, status: "Data updated."});
});
app.listen(80);