forked from moudy/agenda-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (32 loc) · 1.01 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
var path = require('path');
var express = require('express');
var ejs = require('ejs');
var api = require('./lib/api');
module.exports = function (agenda, options) {
options || (options = {});
if (typeof options.poll === 'undefined') {
options.POLL_INTERVAL = 1000;
} else {
options.POLL_INTERVAL = options.poll;
}
var app = express();
var indexHTML = path.join(__dirname, 'lib', 'index.html');
var router = express.Router();
router.get('/:definitionId?', function (req, res) {
var data = {};
options.NAMESPACE = req.originalUrl.replace(/(^\/|\/$)/g, '');
if(options.ASSET_HOST) {
options.ASSETS_NAMESPACE = options.ASSET_HOST + '/' + options.NAMESPACE;
} else {
options.ASSETS_NAMESPACE = '/' + options.NAMESPACE;
}
data.options = options;
ejs.renderFile(indexHTML, data, function (err, html) {
res.send(html);
});
});
app.use('/assets', express.static(path.join(__dirname, 'assets')));
app.use(api(agenda));
app.use(router);
return app;
};