forked from svrjs/svrjs
Replace ES5-style functions with ES6-style ones
This commit is contained in:
parent
09e33a2265
commit
0aa4f9df2b
3 changed files with 15 additions and 15 deletions
|
@ -44,7 +44,7 @@ function clientErrorHandler(err, socket) {
|
|||
if (err.code === "ECONNRESET" || !socket.writable) {
|
||||
return;
|
||||
}
|
||||
socket.end(x, function () {
|
||||
socket.end(x, () => {
|
||||
try {
|
||||
socket.destroy();
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
|
@ -60,9 +60,9 @@ function clientErrorHandler(err, socket) {
|
|||
headers = Object.assign({}, headers);
|
||||
headers["Date"] = new Date().toGMTString();
|
||||
headers["Connection"] = "close";
|
||||
Object.keys(headers).forEach(function (headername) {
|
||||
Object.keys(headers).forEach((headername) => {
|
||||
if (headername.toLowerCase() == "set-cookie") {
|
||||
headers[headername].forEach(function (headerValueS) {
|
||||
headers[headername].forEach((headerValueS) => {
|
||||
if (
|
||||
// eslint-disable-next-line no-control-regex
|
||||
headername.match(/[^\x09\x20-\x7e\x80-\xff]|.:/) ||
|
||||
|
@ -105,7 +105,7 @@ function clientErrorHandler(err, socket) {
|
|||
locmessage: (msg) => serverconsole.locmessage(msg, reqId),
|
||||
};
|
||||
|
||||
socket.on("close", function (hasError) {
|
||||
socket.on("close", (hasError) => {
|
||||
if (
|
||||
!hasError ||
|
||||
err.code == "ERR_SSL_HTTP_REQUEST" ||
|
||||
|
@ -114,7 +114,7 @@ function clientErrorHandler(err, socket) {
|
|||
logFacilities.locmessage("Client disconnected.");
|
||||
else logFacilities.locmessage("Client disconnected due to error.");
|
||||
});
|
||||
socket.on("error", function () {});
|
||||
socket.on("error", () => {});
|
||||
|
||||
// Header and footer placeholders
|
||||
let head = "";
|
||||
|
@ -178,7 +178,7 @@ function clientErrorHandler(err, socket) {
|
|||
if (p) callback(p);
|
||||
else {
|
||||
if (errorCode == 404) {
|
||||
fs.access(config.page404, fs.constants.F_OK, function (err) {
|
||||
fs.access(config.page404, fs.constants.F_OK, (err) => {
|
||||
if (err) {
|
||||
fs.access(
|
||||
"." + errorCode.toString(),
|
||||
|
@ -229,7 +229,7 @@ function clientErrorHandler(err, socket) {
|
|||
getErrorFileName(list, callback, _i + 1);
|
||||
return;
|
||||
} else {
|
||||
fs.access(list[_i].path, fs.constants.F_OK, function (err) {
|
||||
fs.access(list[_i].path, fs.constants.F_OK, (err) => {
|
||||
if (err) {
|
||||
getErrorFileName(list, callback, _i + 1);
|
||||
} 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]")
|
||||
stack = generateErrorStack(stack);
|
||||
if (stack === undefined)
|
||||
|
@ -313,7 +313,7 @@ function clientErrorHandler(err, socket) {
|
|||
);
|
||||
res.end();
|
||||
} else {
|
||||
fs.readFile(errorFile, function (err, data) {
|
||||
fs.readFile(errorFile, (err, data) => {
|
||||
try {
|
||||
if (err) throw err;
|
||||
res.writeHead(errorCode, http.STATUS_CODES[errorCode], cheaders);
|
||||
|
|
|
@ -79,7 +79,7 @@ function requestHandler(req, res) {
|
|||
if (table == undefined) table = this.tHeaders;
|
||||
if (table == undefined) table = {};
|
||||
table = Object.assign({}, table);
|
||||
Object.keys(table).forEach(function (key) {
|
||||
Object.keys(table).forEach((key) => {
|
||||
const al = key.toLowerCase();
|
||||
if (
|
||||
al == "transfer-encoding" ||
|
||||
|
@ -343,7 +343,7 @@ function requestHandler(req, res) {
|
|||
if (p) callback(p);
|
||||
else {
|
||||
if (errorCode == 404) {
|
||||
fs.access(config.page404, fs.constants.F_OK, function (err) {
|
||||
fs.access(config.page404, fs.constants.F_OK, (err) => {
|
||||
if (err) {
|
||||
fs.access(
|
||||
"." + errorCode.toString(),
|
||||
|
@ -400,7 +400,7 @@ function requestHandler(req, res) {
|
|||
getErrorFileName(list, callback, _i + 1);
|
||||
return;
|
||||
} else {
|
||||
fs.access(list[_i].path, fs.constants.F_OK, function (err) {
|
||||
fs.access(list[_i].path, fs.constants.F_OK, (err) => {
|
||||
if (err) {
|
||||
getErrorFileName(list, callback, _i + 1);
|
||||
} else {
|
||||
|
@ -410,7 +410,7 @@ function requestHandler(req, res) {
|
|||
}
|
||||
};
|
||||
|
||||
getErrorFileName(config.errorPages, function (errorFile) {
|
||||
getErrorFileName(config.errorPages, (errorFile) => {
|
||||
// Generate error stack if not provided
|
||||
if (Object.prototype.toString.call(stack) === "[object Error]")
|
||||
stack = generateErrorStack(stack);
|
||||
|
@ -442,7 +442,7 @@ function requestHandler(req, res) {
|
|||
cheaders["Allow"] = "GET, POST, HEAD, OPTIONS";
|
||||
|
||||
// Read the error file and replace placeholders with error information
|
||||
fs.readFile(errorFile, function (err, data) {
|
||||
fs.readFile(errorFile, (err, data) => {
|
||||
try {
|
||||
if (err) throw err;
|
||||
res.writeHead(errorCode, http.STATUS_CODES[errorCode], cheaders);
|
||||
|
|
|
@ -38,7 +38,7 @@ function serverErrorHandler(err, isRedirect, server, start) {
|
|||
} catch (err) {
|
||||
// Probably main process exited
|
||||
}
|
||||
setTimeout(function () {
|
||||
setTimeout(() => {
|
||||
const errno = os.constants.errno[err.code];
|
||||
process.exit(errno !== undefined ? errno : 1);
|
||||
}, 50);
|
||||
|
|
Reference in a new issue