diff --git a/lib/pingback.js b/lib/pingback.js index 9334cfd..9e550e5 100644 --- a/lib/pingback.js +++ b/lib/pingback.js @@ -10,12 +10,10 @@ const https = require('https'); const querystring = require('querystring'); module.exports = (config) => { - const cfg = config; - const url = cfg.url; - const parsedUrl = URL.parse(url); - const client = parsedUrl.protocol === 'https:' ? https : http; + const url = config.url; + const parsedUrl = !url ? null : URL.parse(url); - if (!parsedUrl.hostname) { + if (!parsedUrl || !parsedUrl.hostname) { return { ok: false, error: 'No hostname found for ' + url, @@ -49,8 +47,8 @@ module.exports = (config) => { 'Content-Length': postData.length } }; - - var req = client.request(httpOptions, (res) => { + const client = parsedUrl.protocol === 'https:' ? https : http; + const req = client.request(httpOptions, (res) => { let data = ''; res.setEncoding('utf8');