From 0f460c840b97458539218b734831cca6da8ca737 Mon Sep 17 00:00:00 2001 From: qfdk Date: Sat, 2 Mar 2024 21:44:59 +0100 Subject: [PATCH] fix : login configuration use dotenv --- app.js | 2 ++ config.js | 4 ---- middlewares/security.js | 6 ++---- package.json | 3 ++- yarn.lock | 5 +++++ 5 files changed, 11 insertions(+), 9 deletions(-) delete mode 100644 config.js diff --git a/app.js b/app.js index e18481f..cb549f8 100644 --- a/app.js +++ b/app.js @@ -1,3 +1,5 @@ +require('dotenv').config(); + const express = require('express'); const path = require('path'); const bodyParser = require('body-parser'); diff --git a/config.js b/config.js deleted file mode 100644 index c714445..0000000 --- a/config.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - 'username': process.env.EDW_USERNAME || 'admin', - 'password': process.env.EDW_PASSWORD || 'admin' -}; diff --git a/middlewares/security.js b/middlewares/security.js index 240aeab..24e09a7 100644 --- a/middlewares/security.js +++ b/middlewares/security.js @@ -1,13 +1,11 @@ -const config = require('../config'); - const checkUser = (req, res, next) => { res.locals.isLogin = false; if (req.session.isLogin) { res.locals.isLogin = true; next(); } else { - const username = config.username, - password = config.password; + const username = process.env.EDW_USERNAME, + password = process.env.EDW_PASSWORD; if (req.body.username === username && req.body.password === password) { req.session.isLogin = true; res.redirect('/'); diff --git a/package.json b/package.json index 995f58e..f6bf13e 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "express-session": "^1.17.1", "express-status-monitor": "^1.2.8", "serve-favicon": "^2.4.5", - "socket.io": "2.4.1" + "socket.io": "2.4.1", + "dotenv": "^16.4.5" }, "devDependencies": { "nodemon": "^3.0.3" diff --git a/yarn.lock b/yarn.lock index 4842ea7..e6ffb27 100644 --- a/yarn.lock +++ b/yarn.lock @@ -361,6 +361,11 @@ dockerode@^4.0.2: docker-modem "^5.0.3" tar-fs "~2.0.1" +dotenv@^16.4.5: + version "16.4.5" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.5.tgz#cdd3b3b604cb327e286b4762e13502f717cb099f" + integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg== + ee-first@1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"