Skip to content

Commit 0c08035

Browse files
Prepend http protocol
1 parent 2c210ed commit 0c08035

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

pdf-service.js

Lines changed: 11 additions & 1 deletion
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+
const url = withHttp(req.query.url);
6464
console.log('/from-url');
6565

6666
if (!url) {
@@ -82,6 +82,16 @@ app.get('/from-url', async (req, res) => {
8282
}
8383
});
8484

85+
function withHttp (url) {
86+
if (!url) {
87+
return;
88+
}
89+
90+
return !/^https?:\/\//i.test(url)
91+
? `http://${url}`
92+
: url;
93+
}
94+
8595
function deliverJson(res, resp, status = 200) {
8696
res.status(status).contentType('json').send(resp);
8797
}

0 commit comments

Comments
 (0)