From 469f636c370823303aa30aa91d0f2135f7896a59 Mon Sep 17 00:00:00 2001 From: Nicolas Brassard Date: Mon, 26 Nov 2018 12:05:41 -0500 Subject: [PATCH] Make pingbackUrl optional in the config file Fixes #40 --- lib/pingback.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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');