diff --git a/src/handlers/clientErrorHandler.js b/src/handlers/clientErrorHandler.js index 2a44649..ff7e5ca 100644 --- a/src/handlers/clientErrorHandler.js +++ b/src/handlers/clientErrorHandler.js @@ -204,21 +204,17 @@ function clientErrorHandler(err, socket) { } }); } else { - fs.access( - "." + errorCode.toString(), - fs.constants.F_OK, - (err) => { - try { - if (err) { - callback(errorCode.toString() + ".html"); - } else { - callback("." + errorCode.toString()); - } - } catch (err2) { - callServerError(500, err2); + fs.access("." + errorCode.toString(), fs.constants.F_OK, (err) => { + try { + if (err) { + callback(errorCode.toString() + ".html"); + } else { + callback("." + errorCode.toString()); } - }, - ); + } catch (err2) { + callServerError(500, err2); + } + }); } } }; diff --git a/src/handlers/requestHandler.js b/src/handlers/requestHandler.js index e947d80..ffef689 100644 --- a/src/handlers/requestHandler.js +++ b/src/handlers/requestHandler.js @@ -54,7 +54,7 @@ function requestHandler(req, res) { return true; } }); - if (vhostP && vhostP.headers) ph = {...ph, ...vhostP.headers}; + if (vhostP && vhostP.headers) ph = { ...ph, ...vhostP.headers }; } Object.keys(ph).forEach((phk) => { if (typeof ph[phk] == "string") @@ -369,24 +369,20 @@ function requestHandler(req, res) { } }); } else { - fs.access( - "." + errorCode.toString(), - fs.constants.F_OK, - (err) => { - try { - if (err) { - callback(errorCode.toString() + ".html"); - } else { - callback("." + errorCode.toString()); - } - } catch (err2) { - res.error(500, err2); + fs.access("." + errorCode.toString(), fs.constants.F_OK, (err) => { + try { + if (err) { + callback(errorCode.toString() + ".html"); + } else { + callback("." + errorCode.toString()); } - }, - ); + } catch (err2) { + res.error(500, err2); + } + }); } } - } + }; if (!_i) _i = 0; if (_i >= list.length) { @@ -412,7 +408,7 @@ function requestHandler(req, res) { } }); } - } + }; getErrorFileName(config.errorPages, function (errorFile) { // Generate error stack if not provided diff --git a/src/utils/deepClone.js b/src/utils/deepClone.js index dbaa979..4f21e63 100644 --- a/src/utils/deepClone.js +++ b/src/utils/deepClone.js @@ -1,37 +1,43 @@ // Function to deep clone an object or array -function deepClone(obj, _objectsArray, _clonesArray) { - if (!_objectsArray) _objectsArray = []; - if (!_clonesArray) _clonesArray = []; +function deepClone(obj) { if (typeof obj !== "object" || obj === null) { return obj; } - let objectsArrayIndex = _objectsArray.indexOf(obj); - if (objectsArrayIndex != -1) { - return _clonesArray[objectsArrayIndex]; - } + const recurse = (obj, _objectsArray, _clonesArray) => { + if (!_objectsArray) _objectsArray = []; + if (!_clonesArray) _clonesArray = []; - let clone; + let objectsArrayIndex = _objectsArray.indexOf(obj); + if (objectsArrayIndex != -1) { + return _clonesArray[objectsArrayIndex]; + } - if (Array.isArray(obj)) { - clone = []; - _objectsArray.push(obj); - _clonesArray.push(clone); - obj.forEach((item, index) => { - clone[index] = deepClone(item, _objectsArray, _clonesArray); - }); - } else { - clone = {}; - _objectsArray.push(obj); - _clonesArray.push(clone); - Object.keys(obj).forEach((key) => { - if (Object.prototype.hasOwnProperty.call(obj, key)) { - clone[key] = deepClone(obj[key], _objectsArray, _clonesArray); - } - }); - } + let clone; - return clone; + if (Array.isArray(obj)) { + clone = []; + _objectsArray.push(obj); + _clonesArray.push(clone); + obj.forEach((item, index) => { + clone[index] = recurse(item, _objectsArray, _clonesArray); + }); + } else { + clone = {}; + _objectsArray.push(obj); + _clonesArray.push(clone); + Object.keys(obj).forEach((key) => { + if (Object.prototype.hasOwnProperty.call(obj, key)) { + clone[key] = + typeof obj[key] !== "object" || obj[key] === null + ? obj[key] + : recurse(obj[key], _objectsArray, _clonesArray); + } + }); + } + return clone; + }; + return recurse(obj); } module.exports = deepClone;