From a7ac58e182cb8d11d1fcd539ade099e4a95bbd4b Mon Sep 17 00:00:00 2001 From: Dave Winer Date: Mon, 31 Aug 2015 19:23:02 -0400 Subject: [PATCH] v0.68 --- README.md | 4 ++++ lib/utils.js | 19 ++++++++++++++++++- pagepark.js | 18 +++++++++++------- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0b0e40b..a1740b8 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,10 @@ There will always be more work to do here. ;-) #### Updates +##### v0.68 8/31/15 by DW + +Small change in error handling when we delegate a request. The previous method would cause PagePark to crash if the app we're trying to delegate to isn't running. Thanks to Dan MacTough for the help fixing this. ;-) + ##### v0.67 7/30/15 by DW New redirect feature for individual pages. diff --git a/lib/utils.js b/lib/utils.js index 6319fd9..7588185 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -835,7 +835,7 @@ function sleepTillTopOfMinute (callback) { //11/22/14 by DW if (ctseconds == 0) { ctseconds = 60; } - setTimeout (everyMinute, ctseconds * 1000); + setTimeout (callback, ctseconds * 1000); //8/13/15 by DW -- was hard-coded to "everyMinute" ignored the callback param, fixed } function scheduleNextRun (callback, ctMillisecsBetwRuns) { //11/27/14 by DW var ctmilliseconds = ctMillisecsBetwRuns - (Number (new Date ().getMilliseconds ()) + ctMillisecsBetwRuns) % ctMillisecsBetwRuns; @@ -949,4 +949,21 @@ function gigabyteString (num) { //1/24/15 by DW function dateToNumber (theDate) { //2/15/15 by DW return (Number (new Date (theDate))); } +function getFileModDate (f, callback) { //8/26/15 by DW + fs.exists (f, function (flExists) { + if (flExists) { + fs.stat (f, function (err, stats) { + if (err) { + callback (undefined); + } + else { + callback (new Date (stats.mtime).toString ()); + } + }); + } + else { + callback (undefined); + } + }); + } diff --git a/pagepark.js b/pagepark.js index 71fd60f..62c3f9a 100644 --- a/pagepark.js +++ b/pagepark.js @@ -1,4 +1,4 @@ -var myVersion = "0.67c", myProductName = "PagePark"; +var myVersion = "0.68a", myProductName = "PagePark"; /* The MIT License (MIT) Copyright (c) 2014-2015 Dave Winer @@ -374,13 +374,17 @@ function handleHttpRequest (httpRequest, httpResponse) { "X-Forwarded-For": httpRequest.connection.remoteAddress } }; - try { - httpRequest.pipe (request (theRequest)).pipe (httpResponse); - } - catch (tryError) { - httpResponse.writeHead (500, {"Content-Type": "text/plain"}); - httpResponse.end (tryError.message); + function handleError (err) { + if (err) { + console.log ("delegateRequest: error == " + err.message); + httpResponse.writeHead (500, {"Content-Type": "text/plain"}); + httpResponse.end (tryError.message); + } } + var req = httpRequest.pipe (request (theRequest)); + req.on ("error", handleError); + req.pipe (httpResponse).on ("error", handleError); + } function findMappedDomain (domain, callback) { //5/23/15 by DW for (var x in pageparkPrefs.domainMap) {