diff --git a/.codexdocsrc.sample b/.codexdocsrc.sample index 715cb16..94ad051 100644 --- a/.codexdocsrc.sample +++ b/.codexdocsrc.sample @@ -8,6 +8,7 @@ {"title": "Support Project", "uri": "/support"} ], "landingFrameSrc": "https://codex.so/editor?frame=1", + "startPage": "codex", "misprintsChatId": "12344564", "yandexMetrikaId": "" } diff --git a/config/production.json b/config/production.json index fe19bd3..c91a562 100644 --- a/config/production.json +++ b/config/production.json @@ -2,6 +2,5 @@ "port": 3000, "database": ".db", "uploads": "public/uploads", - "secret": "iamasecretstring", - "startPage": "codex" + "secret": "iamasecretstring" } diff --git a/src/app.js b/src/app.js index 8ef3210..1b7a746 100644 --- a/src/app.js +++ b/src/app.js @@ -22,6 +22,11 @@ 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 6169bbb..3b33f2c 100644 --- a/src/routes/home.js +++ b/src/routes/home.js @@ -1,12 +1,12 @@ const express = require('express'); const verifyToken = require('./middlewares/token'); const router = express.Router(); -const config = require('../../config/index'); /* GET home page. */ router.get('/', verifyToken, async (req, res) => { - if (config.startPage) { - return res.redirect(config.startPage); + console.log(res.locals); + if (res.locals.startPage) { + return res.redirect(res.locals.startPage); } res.render('pages/index', { isAuthorized: res.locals.isAuthorized }); });