1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-07-21 14:19:42 +02:00

Implement yaml config (#271)

This commit is contained in:
Nikita Melnikov 2022-09-29 06:41:24 +08:00 committed by GitHub
parent 5a7f1c843b
commit 13762096c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 164 additions and 479 deletions

View file

@ -1,7 +1,7 @@
import express, { Request, Response } from 'express';
import jwt from 'jsonwebtoken';
import config from 'config';
import csrf from 'csurf';
import appConfig from "../utils/appConfig.js";
const router = express.Router();
const csrfProtection = csrf({ cookie: true });
@ -22,7 +22,7 @@ router.get('/auth', csrfProtection, function (req: Request, res: Response) {
*/
router.post('/auth', parseForm, csrfProtection, async (req: Request, res: Response) => {
try {
if (!process.env.PASSWORD) {
if (!appConfig.password) {
res.render('auth', {
title: 'Login page',
header: 'Password not set',
@ -32,7 +32,7 @@ router.post('/auth', parseForm, csrfProtection, async (req: Request, res: Respon
return;
}
if (req.body.password !== process.env.PASSWORD) {
if (req.body.password !== appConfig.password) {
res.render('auth', {
title: 'Login page',
header: 'Wrong password',
@ -46,7 +46,7 @@ router.post('/auth', parseForm, csrfProtection, async (req: Request, res: Respon
iss: 'Codex Team',
sub: 'auth',
iat: Date.now(),
}, process.env.PASSWORD + config.get('secret'));
}, appConfig.password + appConfig.auth.secret);
res.cookie('authToken', token, {
httpOnly: true,