From 4b3f164ddae97f930b028cc27813445563abf37b Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Wed, 24 Nov 2021 00:33:20 +0200 Subject: [PATCH 1/6] Update eslint config --- .eslintrc.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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" ] } } From f4669231cf62ccb174a813cf5ca9147a5b1fe715 Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Wed, 24 Nov 2021 00:33:36 +0200 Subject: [PATCH 2/6] Add editor config --- .editorconfig | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .editorconfig 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 From f2f236aab92ed973fa4decb50838cddf3726687e Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Wed, 24 Nov 2021 00:33:52 +0200 Subject: [PATCH 3/6] Fix code style --- JavaScript/client.js | 2 +- JavaScript/server.js | 18 +++++++++--------- JavaScript/storage.js | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) 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..94125d9 100644 --- a/JavaScript/server.js +++ b/JavaScript/server.js @@ -7,16 +7,16 @@ 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..3942632 100644 --- a/JavaScript/storage.js +++ b/JavaScript/storage.js @@ -6,7 +6,7 @@ const v8 = require('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')); From 0697dde802fca17fac610fd3ea4460ea30247955 Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Wed, 24 Nov 2021 00:36:34 +0200 Subject: [PATCH 4/6] Update license --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 4d64d18..e6004fa 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019-2020 How.Programming.Works contributors +Copyright (c) 2019-2021 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 From 1e4d3e1dc244afafd4d962ac5c38aa4e6305a802 Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Mon, 3 Oct 2022 23:18:47 +0300 Subject: [PATCH 5/6] Add node: for internal modules --- JavaScript/server.js | 2 +- JavaScript/storage.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/JavaScript/server.js b/JavaScript/server.js index 94125d9..daa7125 100644 --- a/JavaScript/server.js +++ b/JavaScript/server.js @@ -1,6 +1,6 @@ 'use strict'; -const http = require('http'); +const http = require('node:http'); const Client = require('./client.js'); const Session = require('./session.js'); diff --git a/JavaScript/storage.js b/JavaScript/storage.js index 3942632..a114315 100644 --- a/JavaScript/storage.js +++ b/JavaScript/storage.js @@ -1,8 +1,8 @@ '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`; From 7f52ee67cec6928ee5722dd64782a70b69d53555 Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Mon, 3 Oct 2022 23:18:53 +0300 Subject: [PATCH 6/6] Update license --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index e6004fa..a92a662 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019-2021 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