Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pdf-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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);
}
Expand Down