Skip to content

Instantly share code, notes, and snippets.

@Studira Studira/reporter.ts
Created Jun 29, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.