forked from l-lin/angular-datatables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
81 lines (68 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
'use strict';
var _firstNameList = ['Foo', 'Toto', 'Louis', 'Cartman', 'Luke', 'Zed', 'Superman', 'Batman', 'Someone First Name'],
_lastNameList = ['Bar', 'Titi', 'Someone Last Name', 'Kyle', 'Yoda', 'Lara', 'Moliku', 'Whateveryournameis'];
var _randomNumber = function(maxNumber) {
return Math.floor(Math.random() * maxNumber);
};
var _randomInArray = function(array) {
return array[_randomNumber(array.length)];
};
var _userList = [];
for (var index = 0; index < 3000; index++) {
_userList.push({
id: _randomNumber(10000),
firstName: _randomInArray(_firstNameList),
lastName: _randomInArray(_lastNameList)
});
}
var _findData = function (dataList, parameters) {
var _userList = [];
for (var index = 0; index < parameters.length; index++) {
_userList.push({
id: _randomNumber(10000),
firstName: _randomInArray(_firstNameList),
lastName: _randomInArray(_lastNameList)
});
}
return {
draw: parameters.draw,
recordsTotal: _userList.length * 10,
recordsFiltered: _userList.length * 10,
data: _userList
};
};
// -----------
// EXPRESS
// -----------
var bodyParser = require('body-parser');
var express = require('express');
// -----------
// INIT
// -----------
var app = express();
// to support JSON-encoded bodies
app.use(bodyParser.json());
// to support URL-encoded bodies
app.use(bodyParser.urlencoded({
extended: true
}));
// -----------
// ROUTING
// -----------
app.use('/angular-datatables', express.static(__dirname));
app.get('/angular-datatables/data', function(req, res) {
var _userList = [];
for (var index = 0; index < 3000; index++) {
_userList.push({
id: _randomNumber(10000),
firstName: _randomInArray(_firstNameList),
lastName: _randomInArray(_lastNameList)
});
}
res.json(_userList);
});
app.post('/angular-datatables/data/serverSideProcessing', function (req, res) {
var parameters = req.body;
res.json(_findData(_userList, parameters));
});
module.exports = app;