-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.js
68 lines (57 loc) · 2.09 KB
/
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
const winston = require('winston')
require('winston-loggly-bulk')
const packageJson = require('./package.json')
const jsreportPackageJson = require(require.resolve('jsreport/package.json'))
if (!process.env.ip && !process.env.stack) {
console.log('Using local ip address and localdev stack')
process.env.ip = require('ip').address()
process.env.stack = 'localdev'
}
const REQUEST_DISCRIMINATOR = 'context.clientIp'
process.env.extensions_dockerWorkers_discriminatorPath = REQUEST_DISCRIMINATOR
if (process.env.NODE_ENV === 'jsreport-development') {
process.env.extensions_studio_extensionsInDevMode = require('./jsreport.config').name
}
let reporter = require('jsreport')({
rootDirectory: __dirname,
discover: false
})
const extensionsToUse = Object.keys(jsreportPackageJson.dependencies).filter((extName) => {
return extName !== '@jsreport/jsreport-core' && (extName.startsWith('@jsreport/jsreport-') || extName.startsWith('jsreport-'))
})
Object.keys(packageJson.dependencies).forEach((extName) => {
if (
(extName.startsWith('@jsreport/jsreport-') || extName.startsWith('jsreport-')) &&
!extensionsToUse.includes(extName)
) {
extensionsToUse.push(extName)
}
})
for (const extName of extensionsToUse) {
reporter = reporter.use(require(extName)())
}
// use playground extension
reporter.use(require('./')())
if (process.env.JSREPORT_CLI) {
// export jsreport instance to make it possible to use jsreport-cli
module.exports = reporter
} else {
reporter.__electron_html_to__ = () => { }
reporter.init().then(() => {
// cannot use afterConfigLoaded because it is used in jsreport package
if (reporter.options.loggly.token) {
reporter.logger.add(new winston.transports.Loggly({
level: reporter.options.loggly.level,
token: reporter.options.loggly.token,
subdomain: reporter.options.loggly.subdomain,
json: true,
tags: ['playground']
}))
}
// running
}).catch((e) => {
// error during startup
console.error(e.stack)
process.exit(1)
})
}