Skip to content

Commit

Permalink
[Task] #50, cleanup cetntralized; rename token functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Type-Style committed Mar 25, 2024
1 parent 1c1def9 commit 7ee7d6b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import readRouter from '@src/controller/read';
import loginRouter from '@src/controller/login';
import path from 'path';
import logger from '@src/scripts/logger';
import { baseRateLimiter } from './middleware/limit';
import { baseRateLimiter, cleanup as cleanupRateLimitedIps } from './middleware/limit';
import { cleanupCSRF } from "@src/scripts/token";

// configurations
config(); // dotenv
Expand Down Expand Up @@ -75,6 +76,12 @@ const server = app.listen(80, () => {
logger.log(`Server running //localhost:80, ENV: ${process.env.NODE_ENV}`, true);
});

// scheduled cleanup
setInterval(() => {
cleanupCSRF();
cleanupRateLimitedIps();
}, 1000 * 60 * 5);

// catching shutdowns
['SIGINT', 'SIGTERM', 'exit'].forEach((signal) => {
process.on(signal, () => {
Expand Down
4 changes: 2 additions & 2 deletions src/middleware/logged-in.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Request, Response, NextFunction } from 'express';
import { validateToken } from '@src/scripts/token';
import { validateJWT } from '@src/scripts/token';
import { create as createError } from '@src/middleware/error';


export function isLoggedIn(req: Request, res: Response, next: NextFunction) {
const result = validateToken(req);
const result = validateJWT(req);
if (!result.success) {
createError(res, result.status, result.message || "", next)
} else {
Expand Down

0 comments on commit 7ee7d6b

Please sign in to comment.