Skip to content

Commit cddd246

Browse files
authored
Merge pull request #9 from leandroncbrito/verify-http-protocol
Prepend http protocol
2 parents 2c210ed + 8a15cff commit cddd246

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

pdf-service.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ app.post('/from-html', async (req, res) => {
6060

6161
app.get('/from-url', async (req, res) => {
6262
calls.fromUrl++;
63-
const url = req.query.url;
63+
let url = req.query.url;
6464
console.log('/from-url');
6565

6666
if (!url) {
@@ -71,7 +71,7 @@ app.get('/from-url', async (req, res) => {
7171

7272
let pdfFilePath;
7373
try {
74-
pdfFilePath = await generatePdf(url, req.query.media);
74+
pdfFilePath = await generatePdf(withHttp(url), req.query.media);
7575

7676
deliverPdfFile(res, pdfFilePath);
7777
} catch (err) {
@@ -82,6 +82,12 @@ app.get('/from-url', async (req, res) => {
8282
}
8383
});
8484

85+
function withHttp (url) {
86+
return !/^https?:\/\//i.test(url)
87+
? `http://${url}`
88+
: url;
89+
}
90+
8591
function deliverJson(res, resp, status = 200) {
8692
res.status(status).contentType('json').send(resp);
8793
}

0 commit comments

Comments
 (0)