mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-11-11 07:41:04 +00:00
Allow targetUrls without protocol
This commit is contained in:
parent
364993bfcd
commit
256064213b
@ -1,5 +1,6 @@
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import url from 'url';
|
||||
|
||||
import request from 'request';
|
||||
import cheerio from 'cheerio';
|
||||
@ -24,9 +25,7 @@ function optionsFactory(name,
|
||||
userAgent,
|
||||
callback) {
|
||||
|
||||
if (!validator.isURL(targetUrl, {require_protocol: true})) {
|
||||
throw `Your Url ${targetUrl} is invalid!, did you remember to include 'http://'?`;
|
||||
}
|
||||
targetUrl = normalizeUrl(targetUrl);
|
||||
|
||||
if (!width) {
|
||||
width = 1280;
|
||||
@ -109,4 +108,17 @@ function getTitle(url, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function normalizeUrl(testUrl) {
|
||||
// add protocol if protocol not found
|
||||
let normalized = testUrl;
|
||||
const parsed = url.parse(normalized);
|
||||
if (!parsed.protocol) {
|
||||
normalized = 'http://' + normalized;
|
||||
}
|
||||
if (!validator.isURL(normalized, {require_protocol: true})) {
|
||||
throw `Your Url: "${normalized}" is invalid!`;
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
export default optionsFactory;
|
||||
|
Loading…
Reference in New Issue
Block a user