-
Notifications
You must be signed in to change notification settings - Fork 5
/
sample-server.js
70 lines (56 loc) · 1.64 KB
/
sample-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
/**
The sample server for OLAP.js library.
*/
var olap = require('./olap/olap.js');
// olap.js
// alax.js
// Express
var express = require('express');
var url = require('url');
var app = express();
// Middleware
var bodyParser = require('body-parser');
var urlencodedParser = bodyParser.urlencoded({ extended: true });
var jsonParser = bodyParser.json({ extended: false });
var textParser = bodyParser.text();
var rawParser = bodyParser.raw();
app.use(express.static('public'));
//app.use(bodyParser.json());
//app.use(bodyParser.urlencoded({extended:false}));
//app.use(bodyParser.text({ type: 'text/xml' }))
// XMLA entry point
app.post('/xmla', function (req, res) {
var data='';
req.setEncoding('utf8');
req.on('data', function(chunk) {
data += chunk;
});
req.on('end', function() {
console.log(data);
req.body = data;
res.send(olap.xmla(req.body));
});
});
// Discover Metadata
app.get('/discover/metadata', function (req, res) {
var query = url.parse(req.url, true).query;
console.log('Discover metadata cube:',query.cubeName);
res.send(olap.metadata(query.cubeName));
});
// Discover Level Members
app.get('/discover/levelmembers', function (req, res) {
// console.log(req);
res.send(olap.levelmembers(req.body));
});
// Execute
app.post('/execute/execute', urlencodedParser, function (req, res) {
console.log('Execute MDX:',req.body.mdx);
// console.log(req.body);
res.send(olap.execute(req.body));
});
// Server
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});