Se parametrizan los endpoints

main
unknown 2 years ago
parent 8ddc4147f6
commit 586acdc03e
  1. 8
      app.js

@ -56,10 +56,10 @@ app.get('/Invoice', async (req, res) => {
})
})
async function printPDF() {
async function printPDF(id) {
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.goto('http://localhost:9091/Invoice?id=2', { waitUntil: 'networkidle0' });
await page.goto(`http://localhost:${port}/Invoice?id=${id}`, { waitUntil: 'networkidle0' });
const pdf = await page.pdf({
format: 'A4', displayHeaderFooter: true,
headerTemplate: ``,
@ -76,8 +76,8 @@ async function printPDF() {
}
app.get('/getAmazonInvoicePDF', async (req, res) => {
let file = [{ url: "http://localhost:9091/Invoice?id=2", name: 'AmazonInvoice.pdf' }];
printPDF().then(pdf => {
let file = [{ url: `http://localhost:${port}/Invoice?id=${req.query.id}`, name: 'AmazonInvoice.pdf' }];
printPDF(req.query.id).then(pdf => {
res.set({ 'Content-Type': 'application/pdf', 'Content-Length': pdf.length })
res.send(pdf)
})

Loading…
Cancel
Save