mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-10 07:55:24 +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 rcParser from './utils/rcparser';
|
||||||
import routes from './routes';
|
import routes from './routes';
|
||||||
import HttpException from './exceptions/httpException';
|
import HttpException from './exceptions/httpException';
|
||||||
|
import * as dotenv from 'dotenv';
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
const app = express();
|
const app = express();
|
||||||
const config = rcParser.getConfiguration();
|
const config = rcParser.getConfiguration();
|
||||||
|
|
||||||
|
|
|
@ -2,9 +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 * as dotenv from 'dotenv';
|
|
||||||
|
|
||||||
dotenv.config();
|
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const csrfProtection = csrf({ cookie: true });
|
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) => {
|
router.post('/auth', parseForm, csrfProtection, async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
const password = process.env.PASSWORD;
|
|
||||||
|
|
||||||
if (!process.env.PASSWORD) {
|
if (!process.env.PASSWORD) {
|
||||||
res.render('auth', {
|
res.render('auth', {
|
||||||
title: 'Login page',
|
title: 'Login page',
|
||||||
|
@ -37,7 +32,7 @@ router.post('/auth', parseForm, csrfProtection, async (req: Request, res: Respon
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.body.password !== password) {
|
if (req.body.password !== process.env.PASSWORD) {
|
||||||
res.render('auth', {
|
res.render('auth', {
|
||||||
title: 'Login page',
|
title: 'Login page',
|
||||||
header: 'Wrong password',
|
header: 'Wrong password',
|
||||||
|
@ -51,7 +46,7 @@ router.post('/auth', parseForm, csrfProtection, async (req: Request, res: Respon
|
||||||
iss: 'Codex Team',
|
iss: 'Codex Team',
|
||||||
sub: 'auth',
|
sub: 'auth',
|
||||||
iat: Date.now(),
|
iat: Date.now(),
|
||||||
}, password + config.get('secret'));
|
}, process.env.PASSWORD + config.get('secret'));
|
||||||
|
|
||||||
res.cookie('authToken', token, {
|
res.cookie('authToken', token, {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
import * as dotenv from 'dotenv';
|
|
||||||
import config from 'config';
|
import config from 'config';
|
||||||
import { NextFunction, Request, Response } from 'express';
|
import { NextFunction, Request, Response } from 'express';
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
|
|
||||||
dotenv.config();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Middleware for checking jwt token
|
* Middleware for checking jwt token
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue