From 2cfa4e36f820cf6a8e1ab4abb523c15a9fb67fa4 Mon Sep 17 00:00:00 2001 From: N0str Date: Sat, 9 May 2020 14:15:46 +0300 Subject: [PATCH] remove global middleware --- src/app.js | 5 ----- src/routes/home.js | 5 +++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/app.js b/src/app.js index 1b7a746..8ef3210 100644 --- a/src/app.js +++ b/src/app.js @@ -22,11 +22,6 @@ app.use(express.urlencoded({ extended: true })); app.use(cookieParser()); app.use(express.static(path.join(__dirname, '../public'))); -// global middleware to define required local variables -app.use('/', function (req, res, next) { - res.locals.startPage = app.locals.config.startPage; - next(); -}); app.use('/', routes); // catch 404 and forward to error handler app.use(function (req, res, next) { diff --git a/src/routes/home.js b/src/routes/home.js index a7fa282..5cc4c72 100644 --- a/src/routes/home.js +++ b/src/routes/home.js @@ -4,8 +4,9 @@ const router = express.Router(); /* GET home page. */ router.get('/', verifyToken, async (req, res) => { - if (res.locals.startPage) { - return res.redirect(res.locals.startPage); + const config = req.app.locals.config; + if (config.startPage) { + return res.redirect(config.startPage); } res.render('pages/index', { isAuthorized: res.locals.isAuthorized }); });