-
Notifications
You must be signed in to change notification settings - Fork 9
/
backend.js
122 lines (100 loc) · 4.78 KB
/
backend.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* global require */
/* eslint no-console:0 */
var express = require('express'),
bodyParser = require('body-parser'),
cookieParser = require('cookie-parser'),
routesNora = require('./demo/routes/nora'),
//Routes
routesTabs = require('./demo/routes/tabs'),
routesTree = require('./demo/routes/tree'),
routesSelect = require('./demo/routes/select'),
routesTable = require('./demo/routes/table'),
routesUpload = require('./demo/routes/upload'),
dashboardTable = require('./demo/routes/dashboard'),
routesCalendar = require('./demo/routes/calendar'),
routesDialog = require('./demo/routes/dialog'),
routesList = require('./demo/routes/list');
// db
//var db = new lokijs('uda');
module.exports = (PORT) => {
var app = express();
app.on('error', function (er) {
console.error('error', er.stack);
});
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
app.use(cookieParser());
var cors = require('cors');
app.use(cors());
app.use(express.static('./'));
app.get('/', function(req, res){
if (req.cookies.language===undefined){
res.cookie('language' , 'es',{expire : new Date() + 9999});
}
res.redirect('/demo/index.html');
});
app.get('/test', function(req, res){
res.redirect('/spec/specRunner_require.html');
});
app.get('/demo/fragmento1', routesTabs.tabsContent1);
app.get('/demo/fragmento2', routesTabs.tabsContent1);
app.get('/demo/fragmento3', routesTabs.tabsContent1);
app.get('/demo/tab2Fragment', routesTabs.tabsContent2);
app.get('/demo/tab3Fragment', routesTabs.tabsContent3);
//Tree
app.get('/demo/ajaxTree', routesTree.json);
app.get('/demo/tree/remote/json', routesTree.json);
app.get('/demo/tree/remote/xml', routesTree.xml);
// Select
app.get('/demo/selectSimple/remote', routesSelect.selectSimple.remote);
app.get('/demo/selectAutocomplete/remote', routesSelect.autocomplete.remote);
app.get('/demo/remoteEnlazadoProvincia/remote', routesSelect.selectEnlazadoSimple.remoteEnlazadoProvincia);
app.get('/demo/remoteEnlazadoComarca/remote', routesSelect.selectEnlazadoSimple.remoteEnlazadoComarca);
app.get('/demo/remoteEnlazadoLocalidad/remote', routesSelect.selectEnlazadoSimple.remoteEnlazadoLocalidad);
// Form
app.get('/demo/nora/pais', routesNora.pais);
app.get('/demo/nora/autonomia', routesNora.autonomia);
app.get('/demo/nora/provincia', routesNora.provincia);
app.post('/demo/nora', routesNora.submit);
// Upload
app.post('/upload', routesUpload.upload);
// Dashboard
app.get('/dashboard/getAll', dashboardTable.getAll);
app.get('/dashboard/get/:id', dashboardTable.get);
app.post('/dashboard/post', dashboardTable.post);
app.put('/dashboard/put', dashboardTable.put);
//Table
app.post('/demo/table/remote/filter', routesTable.filter);
app.post('/demo/table/remote/search', routesTable.search);
app.put('/demo/table/remote/simple', routesTable.simple);
app.post('/demo/table/remote/edit', routesTable.formEditInline);
app.put('/demo/table/remote/edit', routesTable.formEditInline);
app.post('/demo/table/remote/add', routesTable.formEdit);
app.post('/demo/table/remote/deleteEnd', routesTable.deleteEnd);
app.delete('/demo/table/remote/:id', routesTable.delete);
app.get('/demo/table/remote/:id', routesTable.getReg);
app.get('/demo/table/reset', routesTable.reset);
app.post('/demo/table/remote/editForm', routesTable.editForm);
app.post('/demo/table/remote/inlineEdit', routesTable.inlineEdit);
app.options('/demo/table/remote', function (req, res) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
res.sendStatus(200);
});
//Calendar
app.get('/demo/calendar/events', routesCalendar.getEvents);
app.post('/demo/calendar/events/add', routesCalendar.addEvent);
app.post('/demo/calendar/events/restore', routesCalendar.restore);
//List
app.post('/demo/list/filter', routesList.filter);
app.get('/demo/list/filter/multiFilter/getAll', routesList.multiFilterAll);
app.get('/demo/list/filter/multiFilter/getDefault', routesList.multiFilterDefault);
app.post('/demo/list/filter/multiFilter/add', routesList.multiFilterAdd);
app.post('/demo/list/filter/multiFilter/delete', routesList.multiFilterDelete);
//Dialog
app.get('/demo/dialog/dialogAjax', routesDialog.getHTML);
var server = app.listen(PORT);
console.log(`Listening on port ${PORT}...`);
return server;
};