1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-08-09 15:35:25 +02:00

Changed naming in config, from faviconURL to favicon, changed using app.locals variables

This commit is contained in:
slaveeks 2022-07-06 12:25:09 +03:00
parent 3cab15e514
commit 8e2c4b317e
9 changed files with 21 additions and 25 deletions

View file

@ -87,14 +87,14 @@ yarn test
You can configure application using configs in <code>/config</code> directory. You can configure application using configs in <code>/config</code> directory.
| Property | Role | | Property | Role |
|-------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------| |----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| <code>port</code> | to set port of application | | <code>port</code> | to set port of application |
| <code>database</code> | to name directory with data | | <code>database</code> | to name directory with data |
| <code>rcFile</code> | to set destination of codexdocsrc config file | | <code>rcFile</code> | to set destination of codexdocsrc config file |
| <code>uploads</code> | to set destination of directory to save uploads | | <code>uploads</code> | to set destination of directory to save uploads |
| <code>secret</code> | to set secret | | <code>secret</code> | to set secret |
| <code>faviconURL</code> | to set url to get favicon. Server uploads file by url and saves it to temporary directory. And you can get favicon by /favicon route of application | | <code>favicon</code> | to set url or path to get favicon. Server uploads file by url and saves it to temporary directory. And you can get favicon by /favicon static route of application |
You can configure application using configs in <code>/config</code> directory. You can configure application using configs in <code>/config</code> directory.

View file

@ -4,5 +4,5 @@
"rcFile": "./.codexdocsrc", "rcFile": "./.codexdocsrc",
"uploads": "public/uploads", "uploads": "public/uploads",
"secret": "iamasecretstring", "secret": "iamasecretstring",
"faviconURL": "" "favicon": ""
} }

View file

@ -4,5 +4,5 @@
"rcFile": "./.codexdocsrc", "rcFile": "./.codexdocsrc",
"uploads": "/uploads", "uploads": "/uploads",
"secret": "iamasecretstring", "secret": "iamasecretstring",
"faviconURL": "" "favicon": ""
} }

View file

@ -4,5 +4,5 @@
"rcFile": "./src/test/.codexdocsrc", "rcFile": "./src/test/.codexdocsrc",
"uploads": "public/uploads_test", "uploads": "public/uploads_test",
"secret": "iamasecretstring", "secret": "iamasecretstring",
"faviconURL": "" "favicon": ""
} }

View file

@ -16,7 +16,7 @@ const app = express();
const localConfig = rcParser.getConfiguration(); const localConfig = rcParser.getConfiguration();
// Get url to upload favicon from config // Get url to upload favicon from config
const faviconURL: string = appConfig.get('faviconURL'); const faviconURL: string = appConfig.get('favicon');
app.locals.config = localConfig; app.locals.config = localConfig;
// view engine setup // view engine setup

View file

@ -3,7 +3,6 @@ import Aliases from '../controllers/aliases';
import Pages from '../controllers/pages'; import Pages from '../controllers/pages';
import Alias from '../models/alias'; import Alias from '../models/alias';
import verifyToken from './middlewares/token'; import verifyToken from './middlewares/token';
import app from '../app';
const router = express.Router(); const router = express.Router();
@ -37,7 +36,7 @@ router.get('*', verifyToken, async (req: Request, res: Response) => {
page, page,
pageParent, pageParent,
config: req.app.locals.config, config: req.app.locals.config,
favicon: app.locals.favicon, favicon: req.app.locals.favicon,
}); });
} }
} }

View file

@ -2,7 +2,6 @@ import express, { Request, Response } from 'express';
import jwt from 'jsonwebtoken'; import jwt from 'jsonwebtoken';
import config from 'config'; import config from 'config';
import csrf from 'csurf'; import csrf from 'csurf';
import app from '../app';
const router = express.Router(); const router = express.Router();
const csrfProtection = csrf({ cookie: true }); const csrfProtection = csrf({ cookie: true });
@ -15,7 +14,7 @@ router.get('/auth', csrfProtection, function (req: Request, res: Response) {
res.render('auth', { res.render('auth', {
title: 'Login page', title: 'Login page',
csrfToken: req.csrfToken(), csrfToken: req.csrfToken(),
favicon: app.locals.favicon, favicon: req.app.locals.favicon,
}); });
}); });
@ -29,7 +28,7 @@ router.post('/auth', parseForm, csrfProtection, async (req: Request, res: Respon
title: 'Login page', title: 'Login page',
header: 'Password not set', header: 'Password not set',
csrfToken: req.csrfToken(), csrfToken: req.csrfToken(),
favicon: app.locals.favicon, favicon: req.app.locals.favicon,
}); });
return; return;
@ -40,7 +39,7 @@ router.post('/auth', parseForm, csrfProtection, async (req: Request, res: Respon
title: 'Login page', title: 'Login page',
header: 'Wrong password', header: 'Wrong password',
csrfToken: req.csrfToken(), csrfToken: req.csrfToken(),
favicon: app.locals.favicon, favicon: req.app.locals.favicon,
}); });
return; return;
@ -63,7 +62,7 @@ router.post('/auth', parseForm, csrfProtection, async (req: Request, res: Respon
title: 'Login page', title: 'Login page',
header: 'Password not set', header: 'Password not set',
csrfToken: req.csrfToken(), csrfToken: req.csrfToken(),
favicon: app.locals.favicon favicon: req.app.locals.favicon
}); });
return; return;

View file

@ -1,6 +1,5 @@
import express, { Request, Response } from 'express'; import express, { Request, Response } from 'express';
import verifyToken from './middlewares/token'; import verifyToken from './middlewares/token';
import app from '../app';
const router = express.Router(); const router = express.Router();
@ -12,7 +11,7 @@ router.get('/', verifyToken, async (req: Request, res: Response) => {
return res.redirect(config.startPage); return res.redirect(config.startPage);
} }
res.render('pages/index', { isAuthorized: res.locals.isAuthorized, res.render('pages/index', { isAuthorized: res.locals.isAuthorized,
favicon: app.locals.favicon }); favicon: req.app.locals.favicon });
}); });
export default router; export default router;

View file

@ -3,7 +3,6 @@ import Pages from '../controllers/pages';
import PagesOrder from '../controllers/pagesOrder'; import PagesOrder from '../controllers/pagesOrder';
import verifyToken from './middlewares/token'; import verifyToken from './middlewares/token';
import allowEdit from './middlewares/locals'; import allowEdit from './middlewares/locals';
import app from '../app';
const router = express.Router(); const router = express.Router();
@ -17,7 +16,7 @@ router.get('/page/new', verifyToken, allowEdit, async (req: Request, res: Respon
res.render('pages/form', { res.render('pages/form', {
pagesAvailable, pagesAvailable,
page: null, page: null,
favicon: app.locals.favicon, favicon: req.app.locals.favicon,
}); });
} catch (error) { } catch (error) {
res.status(404); res.status(404);
@ -45,7 +44,7 @@ router.get('/page/edit/:id', verifyToken, allowEdit, async (req: Request, res: R
page, page,
parentsChildrenOrdered, parentsChildrenOrdered,
pagesAvailable, pagesAvailable,
favicon: app.locals.favicon, favicon: req.app.locals.favicon,
}); });
} catch (error) { } catch (error) {
res.status(404); res.status(404);
@ -68,7 +67,7 @@ router.get('/page/:id', verifyToken, async (req: Request, res: Response, next: N
page, page,
pageParent, pageParent,
config: req.app.locals.config, config: req.app.locals.config,
favicon: app.locals.favicon, favicon: req.app.locals.favicon,
}); });
} catch (error) { } catch (error) {
res.status(404); res.status(404);