1
0
Fork 0
forked from svrjs/svrjs

Replace ES5-style functions with ES6-style ones

This commit is contained in:
Dorian Niemiec 2024-08-29 19:17:28 +02:00
parent 09e33a2265
commit 0aa4f9df2b
3 changed files with 15 additions and 15 deletions

View file

@ -44,7 +44,7 @@ function clientErrorHandler(err, socket) {
if (err.code === "ECONNRESET" || !socket.writable) { if (err.code === "ECONNRESET" || !socket.writable) {
return; return;
} }
socket.end(x, function () { socket.end(x, () => {
try { try {
socket.destroy(); socket.destroy();
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
@ -60,9 +60,9 @@ function clientErrorHandler(err, socket) {
headers = Object.assign({}, headers); headers = Object.assign({}, headers);
headers["Date"] = new Date().toGMTString(); headers["Date"] = new Date().toGMTString();
headers["Connection"] = "close"; headers["Connection"] = "close";
Object.keys(headers).forEach(function (headername) { Object.keys(headers).forEach((headername) => {
if (headername.toLowerCase() == "set-cookie") { if (headername.toLowerCase() == "set-cookie") {
headers[headername].forEach(function (headerValueS) { headers[headername].forEach((headerValueS) => {
if ( if (
// eslint-disable-next-line no-control-regex // eslint-disable-next-line no-control-regex
headername.match(/[^\x09\x20-\x7e\x80-\xff]|.:/) || headername.match(/[^\x09\x20-\x7e\x80-\xff]|.:/) ||
@ -105,7 +105,7 @@ function clientErrorHandler(err, socket) {
locmessage: (msg) => serverconsole.locmessage(msg, reqId), locmessage: (msg) => serverconsole.locmessage(msg, reqId),
}; };
socket.on("close", function (hasError) { socket.on("close", (hasError) => {
if ( if (
!hasError || !hasError ||
err.code == "ERR_SSL_HTTP_REQUEST" || err.code == "ERR_SSL_HTTP_REQUEST" ||
@ -114,7 +114,7 @@ function clientErrorHandler(err, socket) {
logFacilities.locmessage("Client disconnected."); logFacilities.locmessage("Client disconnected.");
else logFacilities.locmessage("Client disconnected due to error."); else logFacilities.locmessage("Client disconnected due to error.");
}); });
socket.on("error", function () {}); socket.on("error", () => {});
// Header and footer placeholders // Header and footer placeholders
let head = ""; let head = "";
@ -178,7 +178,7 @@ function clientErrorHandler(err, socket) {
if (p) callback(p); if (p) callback(p);
else { else {
if (errorCode == 404) { if (errorCode == 404) {
fs.access(config.page404, fs.constants.F_OK, function (err) { fs.access(config.page404, fs.constants.F_OK, (err) => {
if (err) { if (err) {
fs.access( fs.access(
"." + errorCode.toString(), "." + errorCode.toString(),
@ -229,7 +229,7 @@ function clientErrorHandler(err, socket) {
getErrorFileName(list, callback, _i + 1); getErrorFileName(list, callback, _i + 1);
return; return;
} else { } else {
fs.access(list[_i].path, fs.constants.F_OK, function (err) { fs.access(list[_i].path, fs.constants.F_OK, (err) => {
if (err) { if (err) {
getErrorFileName(list, callback, _i + 1); getErrorFileName(list, callback, _i + 1);
} else { } else {
@ -239,7 +239,7 @@ function clientErrorHandler(err, socket) {
} }
}; };
getErrorFileName(config.errorPages, function (errorFile) { getErrorFileName(config.errorPages, (errorFile) => {
if (Object.prototype.toString.call(stack) === "[object Error]") if (Object.prototype.toString.call(stack) === "[object Error]")
stack = generateErrorStack(stack); stack = generateErrorStack(stack);
if (stack === undefined) if (stack === undefined)
@ -313,7 +313,7 @@ function clientErrorHandler(err, socket) {
); );
res.end(); res.end();
} else { } else {
fs.readFile(errorFile, function (err, data) { fs.readFile(errorFile, (err, data) => {
try { try {
if (err) throw err; if (err) throw err;
res.writeHead(errorCode, http.STATUS_CODES[errorCode], cheaders); res.writeHead(errorCode, http.STATUS_CODES[errorCode], cheaders);

View file

@ -79,7 +79,7 @@ function requestHandler(req, res) {
if (table == undefined) table = this.tHeaders; if (table == undefined) table = this.tHeaders;
if (table == undefined) table = {}; if (table == undefined) table = {};
table = Object.assign({}, table); table = Object.assign({}, table);
Object.keys(table).forEach(function (key) { Object.keys(table).forEach((key) => {
const al = key.toLowerCase(); const al = key.toLowerCase();
if ( if (
al == "transfer-encoding" || al == "transfer-encoding" ||
@ -343,7 +343,7 @@ function requestHandler(req, res) {
if (p) callback(p); if (p) callback(p);
else { else {
if (errorCode == 404) { if (errorCode == 404) {
fs.access(config.page404, fs.constants.F_OK, function (err) { fs.access(config.page404, fs.constants.F_OK, (err) => {
if (err) { if (err) {
fs.access( fs.access(
"." + errorCode.toString(), "." + errorCode.toString(),
@ -400,7 +400,7 @@ function requestHandler(req, res) {
getErrorFileName(list, callback, _i + 1); getErrorFileName(list, callback, _i + 1);
return; return;
} else { } else {
fs.access(list[_i].path, fs.constants.F_OK, function (err) { fs.access(list[_i].path, fs.constants.F_OK, (err) => {
if (err) { if (err) {
getErrorFileName(list, callback, _i + 1); getErrorFileName(list, callback, _i + 1);
} else { } else {
@ -410,7 +410,7 @@ function requestHandler(req, res) {
} }
}; };
getErrorFileName(config.errorPages, function (errorFile) { getErrorFileName(config.errorPages, (errorFile) => {
// Generate error stack if not provided // Generate error stack if not provided
if (Object.prototype.toString.call(stack) === "[object Error]") if (Object.prototype.toString.call(stack) === "[object Error]")
stack = generateErrorStack(stack); stack = generateErrorStack(stack);
@ -442,7 +442,7 @@ function requestHandler(req, res) {
cheaders["Allow"] = "GET, POST, HEAD, OPTIONS"; cheaders["Allow"] = "GET, POST, HEAD, OPTIONS";
// Read the error file and replace placeholders with error information // Read the error file and replace placeholders with error information
fs.readFile(errorFile, function (err, data) { fs.readFile(errorFile, (err, data) => {
try { try {
if (err) throw err; if (err) throw err;
res.writeHead(errorCode, http.STATUS_CODES[errorCode], cheaders); res.writeHead(errorCode, http.STATUS_CODES[errorCode], cheaders);

View file

@ -38,7 +38,7 @@ function serverErrorHandler(err, isRedirect, server, start) {
} catch (err) { } catch (err) {
// Probably main process exited // Probably main process exited
} }
setTimeout(function () { setTimeout(() => {
const errno = os.constants.errno[err.code]; const errno = os.constants.errno[err.code];
process.exit(errno !== undefined ? errno : 1); process.exit(errno !== undefined ? errno : 1);
}, 50); }, 50);