-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·48 lines (39 loc) · 1.29 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
'use strict';
const path = require('path');
const EngineFactory = require('./lib/enginefactory');
const bpmnLoader = require('./lib/bpmnLoader');
module.exports = function (app, config) {
// if repoPath is specified than try loading files
if (config.repoPath) {
const basePath = path.resolve(config.repoPath);
bpmnLoader(basePath, app);
}
EngineFactory.init(app);
// Creating a singleton EngineFactory
app.engineFactory = EngineFactory;
// Add BPMN Viewer routes
if(config.mountPath){
app.use(config.mountPath, function(req, res, next) {
getDefinitionIds(app)
.then((definitions)=>{
var data = definitions || {};
var render = app.loopback.template(__dirname + '/component/viewer.ejs');
var html = render({data:data});
res.status(200).send(html);
});
});
}
};
function getDefinitionIds(app){
return new Promise(function(resolve, reject){
let Definition = app.loopback.getModelByType('Definition');
Definition.find({ fields : {id:true}}, function(err, result){
if(err){
reject(err);
}
else {
resolve(result);
}
});
})
}