1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-08-04 04:55:22 +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

@ -2,9 +2,9 @@ import { Request, Response, Router } from 'express';
import multer, { StorageEngine } from 'multer';
import mime from 'mime';
import mkdirp from 'mkdirp';
import config from 'config';
import Transport from '../../controllers/transport.js';
import { random16 } from '../../utils/crypto.js';
import appConfig from "../../utils/appConfig.js";
const router = Router();
@ -15,7 +15,7 @@ const router = Router();
*/
const storage: StorageEngine = multer.diskStorage({
destination: (req, file, cb) => {
const dir: string = config.get('uploads') || 'public/uploads';
const dir: string = appConfig.uploads || 'public/uploads';
mkdirp(dir);
cb(null, dir);

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,

View file

@ -1,6 +1,6 @@
import config from 'config';
import { NextFunction, Request, Response } from 'express';
import jwt from 'jsonwebtoken';
import appConfig from "../../utils/appConfig.js";
/**
@ -14,14 +14,14 @@ export default async function verifyToken(req: Request, res: Response, next: Nex
const token = req.cookies.authToken;
try {
if (!process.env.PASSWORD) {
if (!appConfig.password) {
res.locals.isAuthorized = false;
next();
return;
}
const decodedToken = jwt.verify(token, process.env.PASSWORD + config.get('secret'));
const decodedToken = jwt.verify(token, appConfig.password + appConfig.auth.secret);
res.locals.isAuthorized = !!decodedToken;