-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.js
62 lines (54 loc) · 1.5 KB
/
index.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
const q = require('qlik-sse');
const argv = require('yargs')
.options({
allowScript: {default: false},
port: {default: 50051}
}).argv
let allowScript = null
if (argv.allowScript) {
allowScript = {
scriptAggr: true,
scriptAggrStr: true,
scriptAggrEx: true,
scriptAggrExStr: true,
scriptEval: true,
scriptEvalStr: true,
scriptEvalEx: true,
scriptEvalExStr: true,
}
}
// create an instance of the server
const s = q.server({
identifier: 'qcbsse',
version: '0.1.0',
allowScript,
});
var libs = require('require-all')({
dirname : __dirname + '/functions',
recursive : true
})
Object.values(libs).forEach((mod) => {
registerFunction(mod)
})
// start the server
s.start({
port: argv.port
});
// Functions should catch thier own errors. This process.on() is a last
// ditch effort to keep an uncaught function error from crashing the process.
process.on('uncaughtException', (err) => {
console.log(">>> Uncaught Exception: " + err.message)
console.log(err.stack)
});
// Register this function if it contains function metadata
function registerFunction(mod) {
if(mod.functionDefinition && mod.functionConfig) {
console.log('Registering function ' + mod.functionConfig.name || mod.functionDefinition.name)
s.addFunction(mod.functionDefinition, mod.functionConfig)
}
else { // May be a subdirectory, recourse it looking for functions.
Object.values(mod).forEach((submod) => {
registerFunction(submod)
})
}
}