From 453c724e11ece68759b8c0c944a71ae2487e79a2 Mon Sep 17 00:00:00 2001 From: Lars Trieloff Date: Thu, 2 May 2019 14:12:15 +0000 Subject: [PATCH] fix(static): return the original URL in case a static resource cannot get retieved for an ESI include fixes #813 --- static.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/static.js b/static.js index ff060124..051723ae 100644 --- a/static.js +++ b/static.js @@ -266,7 +266,23 @@ function deliverPlain(owner, repo, ref, entry, root, esi = false) { 'X-Static': 'Raw/Static', }, }; - }).catch(rqerror => error(rqerror.response.body.toString(), rqerror.statusCode)); + }).catch(rqerror => { + if (esi) { + // the ESI failed, so we simply fall back to the original URL + // the browser will fetch it again, so let's cache the 404 + // for five minutes, in order to prevent the static function + // from being called too often + return { + statusCode: 404, + headers: { + 'Content-Type': 'text/plain', + 'Cache-Control': 's-max-age=300', + }, + body: entry + } + } + return error(rqerror.response.body.toString(), rqerror.statusCode) + }); } /**