Skip to content

Commit 637d422

Browse files
committed
refactor(): small refactoring to node-express-js and add copyright notice in all files
1 parent 4d78ebe commit 637d422

File tree

13 files changed

+307
-12
lines changed

13 files changed

+307
-12
lines changed

servers/node-express-js/.env

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# ***************************************************************************
2+
# * MAIN (app.js) *
3+
# ***************************************************************************
4+
5+
FRONT_END_PATH=../../dist/client
6+
LOG_FOLDER=logs
7+
8+
LARGE_PAYLOAD_MESSAGE=stop it!
9+
EXPRESS_SESSION_SECRET=keyboard cat
10+
COOKIE_SECRET=dshgdadgjasd
11+
12+
HELMET_HIDE_POWERED_BY=f__k u idiot
13+
HELMET_REFERRER_POLICY=same-origin
14+
HELMET_HPKP_SHA256S_1=AbCdEf123=
15+
HELMET_HPKP_SHA256S_2=ZyXwVu456=
16+
HELMET_HPKP_REPORT_URI=https://example.com/hpkp-report
17+
HELMET_EXPECT_CT_REPORT_URI=https://example.com/expect-ct-report
18+
19+
# 60 minutes (60*60*1000) = 3600000
20+
RATELIMITER_WINDOW_MS=3600000
21+
RATELIMITER_MAX=1000
22+
RATELIMITER_DELAY_AFTER=800
23+
RATELIMITER_DELAY_MS=3000
24+
RATELIMITER_MESSAGE=Too many requests from this IP, please try again after 60 minutes
25+
26+
# ***************************************************************************
27+
# * COMMON (variables used everywhere) *
28+
# ***************************************************************************
29+
30+
JWT_SECRET=db75467dhiuye09476gbznbczo982eyhyfoewhf3g8f764f8yhnjvkdsoifhgwetg7idehuw
31+
SESSION_TIMEOUT_MS=3600000

servers/node-express-js/app.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2017-2019 Stefano Cappa
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
123
'use strict';
224

325
// --------------------------------------------------------
426
// ------------------Init env variables--------------------
527
// --------------------------------------------------------
628
const config = require('./src/config');
7-
if (process.env.NODE_ENV !== 'production') {
29+
if (!config.isProd()) {
830
console.log('config file loaded', config);
931
}
1032
// --------------------------------------------------------
@@ -13,6 +35,7 @@ if (process.env.NODE_ENV !== 'production') {
1335

1436
const logger = require('./src/logger');
1537
logger.warn(`Starting with NODE_ENV=${config.NODE_ENV}`);
38+
logger.verbose(`config.CI is ${config.CI} and isCI is ${config.isCI()}`);
1639

1740
const { findIndex } = require('lodash');
1841
const express = require('express');
@@ -310,7 +333,7 @@ app.use(
310333
app.use((req, res, next) => {
311334
const csrfTokenToSendToFrontEnd = req.csrfToken();
312335
res.cookie('XSRF-TOKEN', csrfTokenToSendToFrontEnd);
313-
return next();
336+
next();
314337
});
315338

316339
// APIs for all route protected with CSRF

servers/node-express-js/bin/www

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
#!/usr/bin/env node
22

3+
// MIT License
4+
//
5+
// Copyright (c) 2017-2019 Stefano Cappa
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in all
15+
// copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
// SOFTWARE.
24+
325
'use strict';
426

527
const config = require('../src/config');

servers/node-express-js/src/config.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2017-2019 Stefano Cappa
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
123
'use strict';
224

325
const path = require('path');
426

5-
const useDotenv = process.env.CI !== 'yes' && process.env.CI !== true;
6-
console.log(`Use dotenv condition is: ${useDotenv}`);
27+
const notInCI = process.env.CI !== 'yes' && process.env.CI !== true;
28+
console.log(`Use dotenv condition is: ${notInCI}, because I cannot use dotenv with CI, so I have to skip it`);
729

8-
if (useDotenv === true) {
30+
if (notInCI === true) {
931
console.log('Initializing dotenv (requires .env/.env_prod file)');
1032
let dotenvName = null;
1133
switch (process.env.NODE_ENV) {
1234
case 'development':
13-
console.log('dotenv read: .env_dev');
14-
dotenvName = '.env_dev';
35+
console.log('dotenv read: .env');
36+
dotenvName = '.env';
1537
break;
1638
case 'test':
17-
console.log('dotenv read: .env_dev (you are running with NODE_ENV=test)');
18-
dotenvName = '.env_dev';
39+
console.log('dotenv read: .env (you are running with NODE_ENV=test)');
40+
dotenvName = '.env';
1941
break;
2042
default:
2143
case 'production':
@@ -41,8 +63,10 @@ if (useDotenv === true) {
4163
module.exports = {
4264
isProd: () => process.env.NODE_ENV === 'production',
4365
isTest: () => process.env.NODE_ENV === 'test',
66+
isCI: () => process.env.CI === 'yes' || process.env.CI === true,
4467

4568
NODE_ENV: process.env.NODE_ENV || 'development',
69+
CI: process.env.CI || 'yes',
4670

4771
FRONT_END_PATH: process.env.FRONT_END_PATH,
4872
PORT: process.env.PORT || process.env.NODE_ENV === 'production' ? 80 : 3000,

servers/node-express-js/src/db.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2017-2019 Stefano Cappa
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
123
'use strict';
224

325
const db = require('./db.json');

servers/node-express-js/src/logger.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2017-2019 Stefano Cappa
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
123
'use strict';
224

325
const config = require('./config');

servers/node-express-js/src/passport.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2017-2019 Stefano Cappa
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
123
'use strict';
224

325
const config = require('./config');

servers/node-express-js/src/routes/apis.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2017-2019 Stefano Cappa
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
123
'use strict';
224

325
module.exports = {

servers/node-express-js/src/routes/controllers/auth.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2017-2019 Stefano Cappa
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
123
'use strict';
224

325
const jwt = require('jsonwebtoken');

servers/node-express-js/src/routes/controllers/keepalive.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2017-2019 Stefano Cappa
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
123
'use strict';
224

325
const logger = require('../../logger');

0 commit comments

Comments
 (0)