mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-09 15:35:25 +02:00
replace multiple dotenv config with one
This commit is contained in:
parent
b2f9147c9a
commit
36b26ed8a7
3 changed files with 4 additions and 9 deletions
|
@ -5,7 +5,9 @@ import morgan from 'morgan';
|
|||
import rcParser from './utils/rcparser';
|
||||
import routes from './routes';
|
||||
import HttpException from './exceptions/httpException';
|
||||
import * as dotenv from 'dotenv';
|
||||
|
||||
dotenv.config();
|
||||
const app = express();
|
||||
const config = rcParser.getConfiguration();
|
||||
|
||||
|
|
|
@ -2,9 +2,6 @@ import express, { Request, Response } from 'express';
|
|||
import jwt from 'jsonwebtoken';
|
||||
import config from 'config';
|
||||
import csrf from 'csurf';
|
||||
import * as dotenv from 'dotenv';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const router = express.Router();
|
||||
const csrfProtection = csrf({ cookie: true });
|
||||
|
@ -25,8 +22,6 @@ router.get('/auth', csrfProtection, function (req: Request, res: Response) {
|
|||
*/
|
||||
router.post('/auth', parseForm, csrfProtection, async (req: Request, res: Response) => {
|
||||
try {
|
||||
const password = process.env.PASSWORD;
|
||||
|
||||
if (!process.env.PASSWORD) {
|
||||
res.render('auth', {
|
||||
title: 'Login page',
|
||||
|
@ -37,7 +32,7 @@ router.post('/auth', parseForm, csrfProtection, async (req: Request, res: Respon
|
|||
return;
|
||||
}
|
||||
|
||||
if (req.body.password !== password) {
|
||||
if (req.body.password !== process.env.PASSWORD) {
|
||||
res.render('auth', {
|
||||
title: 'Login page',
|
||||
header: 'Wrong password',
|
||||
|
@ -51,7 +46,7 @@ router.post('/auth', parseForm, csrfProtection, async (req: Request, res: Respon
|
|||
iss: 'Codex Team',
|
||||
sub: 'auth',
|
||||
iat: Date.now(),
|
||||
}, password + config.get('secret'));
|
||||
}, process.env.PASSWORD + config.get('secret'));
|
||||
|
||||
res.cookie('authToken', token, {
|
||||
httpOnly: true,
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
import * as dotenv from 'dotenv';
|
||||
import config from 'config';
|
||||
import { NextFunction, Request, Response } from 'express';
|
||||
import jwt from 'jsonwebtoken';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
/**
|
||||
* Middleware for checking jwt token
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue