Skip to content

Instantly share code, notes, and snippets.

@Studira
Created June 29, 2016 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Studira/aa63e73271843f9f2c720a37c3c2ae3c to your computer and use it in GitHub Desktop.
Save Studira/aa63e73271843f9f2c720a37c3c2ae3c to your computer and use it in GitHub Desktop.
import * as express from 'express'
const path = require('path')
const fs = require('fs')
let jsreport
export async function initializeReporter(app, server) {
let reportingApp = express()
let config = {
express: { app: reportingApp, server: server },
appPath: '/report',
'static-resources': {
directory: process.cwd() + '/static_resources'
},
wkhtmltopdf: {
'allowLocalFilesAccess': true
},
rootDirectory: process.cwd(),
blobStorage: 'inMemory',
extensions: ['jsrender', 'debug', 'express', 'phantom-pdf', 'wkhtmltopdf', 'static-resources'],
tasks: {
allowedModules: '*',
numberOfWorkers: 2,
strategy: 'dedicated-process',
templateCache: {
max: 100,
enabled: true
}
},
loadConfig: false,
autoTempCleanup: true,
extensionsLocationCache: true
}
app.use('/report', reportingApp)
jsreport = require('jsreport-core')(config)
await jsreport.init()
return jsreport
}
export async function renderReport(report, reportType, reportExt) {
let reportPath = path.join(process.cwd(), 'reports/'.concat(reportExt), reportType.concat('.', reportExt))
let writer = fs.createWriteStream(reportPath)
let reader = await jsreport.render(report)
reader.stream.pipe(writer)
return reader
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment