diff --git a/app.js b/app.js index fa85f52..ee52914 100644 --- a/app.js +++ b/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) })