diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..dde7877
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,12 @@
+# http://editorconfig.org
+root = true
+
+[*]
+end_of_line = lf
+charset = utf-8
+insert_final_newline = true
+trim_trailing_whitespace = true
+
+[{*.js,*.mjs,*.ts,*.json,*.yml}]
+indent_size = 2
+indent_style = space
diff --git a/.eslintrc.json b/.eslintrc.json
index 2a1db6a..69eb1e4 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -213,7 +213,7 @@
],
"arrow-parens": [
"error",
- "as-needed"
+ "always"
],
"arrow-body-style": [
"error",
@@ -263,9 +263,6 @@
"template-curly-spacing": [
"error",
"never"
- ],
- "require-atomic-updates": [
- "off"
]
}
}
diff --git a/JavaScript/client.js b/JavaScript/client.js
index 837a046..8644fa8 100644
--- a/JavaScript/client.js
+++ b/JavaScript/client.js
@@ -6,7 +6,7 @@ const UNIX_EPOCH = 'Thu, 01 Jan 1970 00:00:00 GMT';
const COOKIE_EXPIRE = 'Fri, 01 Jan 2100 00:00:00 GMT';
const COOKIE_DELETE = `=deleted; Expires=${UNIX_EPOCH}; Path=/; Domain=`;
-const parseHost = host => {
+const parseHost = (host) => {
if (!host) return 'no-host-name-in-http-headers';
const portOffset = host.indexOf(':');
if (portOffset > -1) host = host.substr(0, portOffset);
diff --git a/JavaScript/server.js b/JavaScript/server.js
index af50ac8..daa7125 100644
--- a/JavaScript/server.js
+++ b/JavaScript/server.js
@@ -1,22 +1,22 @@
'use strict';
-const http = require('http');
+const http = require('node:http');
const Client = require('./client.js');
const Session = require('./session.js');
const routing = {
'/': async () => '
welcome to homepage
',
- '/start': async client => {
+ '/start': async (client) => {
Session.start(client);
return `Session token is: ${client.token}`;
},
- '/destroy': async client => {
+ '/destroy': async (client) => {
const result = `Session destroyed: ${client.token}`;
Session.delete(client);
return result;
},
- '/api/method1': async client => {
+ '/api/method1': async (client) => {
if (client.session) {
client.session.set('method1', 'called');
return { data: 'example result' };
@@ -24,11 +24,11 @@ const routing = {
return { data: 'access is denied' };
}
},
- '/api/method2': async client => ({
+ '/api/method2': async (client) => ({
url: client.req.url,
headers: client.req.headers,
}),
- '/api/method3': async client => {
+ '/api/method3': async (client) => {
if (client.session) {
return [...client.session.entries()]
.map(([key, value]) => `${key}: ${value}
`)
@@ -40,8 +40,8 @@ const routing = {
const types = {
object: JSON.stringify,
- string: s => s,
- number: n => n.toString(),
+ string: (s) => s,
+ number: (n) => n.toString(),
undefined: () => 'not found',
};
@@ -58,13 +58,13 @@ http.createServer(async (req, res) => {
res.end('Not found 404');
return;
}
- handler(client).then(data => {
+ handler(client).then((data) => {
const type = typeof data;
const serializer = types[type];
const result = serializer(data);
client.sendCookie();
res.end(result);
- }, err => {
+ }, (err) => {
res.statusCode = 500;
res.end('Internal Server Error 500');
console.log(err);
diff --git a/JavaScript/storage.js b/JavaScript/storage.js
index 3f87f03..a114315 100644
--- a/JavaScript/storage.js
+++ b/JavaScript/storage.js
@@ -1,12 +1,12 @@
'use strict';
-const fs = require('fs');
-const path = require('path');
-const v8 = require('v8');
+const fs = require('node:fs');
+const path = require('node:path');
+const v8 = require('node:v8');
const PATH = `${__dirname}/sessions`;
-const safePath = fn => (token, ...args) => {
+const safePath = (fn) => (token, ...args) => {
const callback = args[args.length - 1];
if (typeof token !== 'string') {
callback(new Error('Invalid session token'));
diff --git a/LICENSE b/LICENSE
index 4d64d18..a92a662 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2019-2020 How.Programming.Works contributors
+Copyright (c) 2019-2022 How.Programming.Works contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal