diff --git a/pdf-service.js b/pdf-service.js index f555e63..c8fcb9a 100644 --- a/pdf-service.js +++ b/pdf-service.js @@ -60,7 +60,7 @@ app.post('/from-html', async (req, res) => { app.get('/from-url', async (req, res) => { calls.fromUrl++; - const url = req.query.url; + let url = req.query.url; console.log('/from-url'); if (!url) { @@ -71,7 +71,7 @@ app.get('/from-url', async (req, res) => { let pdfFilePath; try { - pdfFilePath = await generatePdf(url, req.query.media); + pdfFilePath = await generatePdf(withHttp(url), req.query.media); deliverPdfFile(res, pdfFilePath); } catch (err) { @@ -82,6 +82,12 @@ app.get('/from-url', async (req, res) => { } }); +function withHttp (url) { + return !/^https?:\/\//i.test(url) + ? `http://${url}` + : url; +} + function deliverJson(res, resp, status = 200) { res.status(status).contentType('json').send(resp); }