Skip to content

Commit

Permalink
Fix some compatibility issues after upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
aminlatifi committed Jan 28, 2024
1 parent 4edc3cd commit e1aff2f
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"express": "^4.18.2",
"express-formidable": "^1.2.0",
"express-rate-limit": "^7.1.5",
"express-session": "^1.17.2",
"express-session": "^1.17.3",
"form-data": "^3.0.1",
"google-spreadsheet": "^3.2.0",
"graphql": "16.8.1",
Expand Down
5 changes: 2 additions & 3 deletions src/redis.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { RedisOptions } from 'ioredis';
// tslint:disable-next-line:no-var-requires
const Redis = require('ioredis');
import { RedisOptions, Redis } from 'ioredis';

export const redisConfig: RedisOptions = {
port: Number(process.env.REDIS_PORT) || 6379,
host: process.env.REDIS_HOST || 'localhost',
Expand Down
9 changes: 2 additions & 7 deletions src/server/adminJs/adminJs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,18 @@ import { featuredUpdateTab } from './tabs/featuredUpdateTab';
import { generateTokenTab } from './tabs/tokenTab';
import { donationTab } from './tabs/donationTab';
import { projectVerificationTab } from './tabs/projectVerificationTab';
import { ResourceActions } from './adminJsPermissions';
import { qfRoundTab } from './tabs/qfRoundTab';
import { qfRoundHistoryTab } from './tabs/qfRoundHistoryTab';

// use redis for session data instead of in-memory storage
// tslint:disable-next-line:no-var-requires
// tslint:disable-next-line:no-var-requires
const session = require('express-session');
// tslint:disable-next-line:no-var-requires
const RedisStore = require('connect-redis')(session);
const RedisStore = require('connect-redis').default;

// tslint:disable-next-line:no-var-requires
const cookie = require('cookie');
// tslint:disable-next-line:no-var-requires
const cookieParser = require('cookie-parser');
const secret = config.get('ADMIN_BRO_COOKIE_SECRET') as string;
const adminJsCookie = 'adminjs';

adminJs.registerAdapter({ Database, Resource });

export const getAdminJsRouter = async () => {
Expand Down
6 changes: 3 additions & 3 deletions src/server/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
import config from '../config';
import { rateLimit } from 'express-rate-limit';
import RedisStore from 'rate-limit-redis';
import { RedisStore } from 'rate-limit-redis';
import { ApolloServer } from '@apollo/server';
import { expressMiddleware } from '@apollo/server/express4';
import { ApolloServerPluginSchemaReporting } from '@apollo/server/plugin/schemaReporting';
Expand Down Expand Up @@ -212,8 +212,8 @@ export async function bootstrap() {
const limiter = rateLimit({
store: new RedisStore({
prefix: 'rate-limit:',
client: redis,
// see Configuration
// @ts-expect-error - Known issue: the `call` function is not present in @types/ioredis
sendCommand: (...args: string[]) => redis.call(...args), // see Configuration
}),
windowMs: 60 * 1000, // 1 minutes
max: Number(process.env.ALLOWED_REQUESTS_PER_MINUTE), // limit each IP to 40 requests per windowMs
Expand Down
2 changes: 1 addition & 1 deletion src/utils/createConfirmationUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import config from '../config';

export const createConfirmationUrl = async (userId: number) => {
const token = v4();
await redis.set(confirmUserPrefix + token, userId, 'ex', 60 * 60 * 24); // 1 day expiration
await redis.set(confirmUserPrefix + token, userId, 'EX', 60 * 60 * 24); // 1 day expiration

return `http://${config.get('WEBSITE_URL')}/user/confirm/${token}`;
};

0 comments on commit e1aff2f

Please sign in to comment.