Handlebars does not render

0

I have an api on Node and the front in vue. I need to generate some pdf files in the back but the handlebars does not render past information. Just the static html that is already there.

const puppeteer = require('puppeteer');
const fs = require('fs-extra');
const hbs = require('handlebars');
const path = require('path');

const compile = async (fileName, data) => {

    const filePath = path.join(process.cwd(), 'src/templates', '${fileName}.hbs');
    const html = await fs.readFile(filePath, 'utf-8');
    return hbs.compile(html)(data);
}

exports.folhaPonto = async () => {
    try {
        const browser = await puppeteer.launch();
        const page = await browser.newPage();

        var d = {
            "mes": "julho",
            "author": "Felipe Paz"
        }

        let content = await compile('folha_ponto', d);
        console.log(content);

        await page.setContent(content);
        await page.emulateMedia('screen');
        await page.pdf({
            path: 'dist/pdf/teste.pdf',
            format: 'A4',
            printBackground: true
        })

        console.log('done');
        await browser.close();

    } catch (error) {
        console.log('Errors => ', error);
    }
};

This is my service that is called in my controller (below):

const folhaPonto = require('../../../services/folha_ponto');

exports.folhaPonto = async (req, res, next) => {

    let d = await folhaPonto.folhaPonto();

    res.status(200).send('gerada folha ponto');
}

However, information passed in% with% does not render. PDF is created normally but without the information I need. Could someone tell me the error?

    
asked by anonymous 30.07.2018 / 23:22

0 answers