Skip to content

Commit

Permalink
Provide config to switch between in-memory and redis cache. (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmoy12c authored Sep 12, 2023
1 parent 1bf3687 commit 3a5f742
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ import * as redisStore from 'cache-manager-redis-store';
}),
TerminusModule,
CacheModule.register({
store: redisStore,
host: process.env.TRANSPORT_SOCKET_CACHE_HOST,
port: process.env.TRANSPORT_SOCKET_CACHE_PORT,
store: config().app.cacheStore == 'redis' ? redisStore : 'memory',
host: config().app.cacheStore == 'redis' ? config().app.redisHost : '',
port: config().app.cacheStore == 'redis' ? config().app.redisPort : '',
max: 200000,
ttl: 86400,
}),
Expand Down
1 change: 1 addition & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const config = () => ({
app: {
redisPort: process.env.REDIS_PORT || 6380,
redisHost: process.env.REDIS_HOST || '0.0.0.0',
cacheStore: process.env.CACHE_STORE || 'memory',
port: process.env.SERVER_PORT || 3005,
bot_session_event: process.env.SKT_SESSION_EVT || 'session',
socket_timeout: process.env.SKT_TIMEOUT || 60000,
Expand Down
13 changes: 7 additions & 6 deletions src/guard/ws.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import * as jwt from 'jsonwebtoken';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const jwksClient = require('jwks-rsa');

const client = jwksClient({
jwksUri: process.env.TRANSPORT_SOCKET_JWT_AUTH_URL,
requestHeaders: {}, // Optional
timeout: 30000, // Defaults to 30s
});

const getKey = (header, callback) => {
let client = jwksClient({
jwksUri: process.env.TRANSPORT_SOCKET_JWT_AUTH_URL,
requestHeaders: {}, // Optional
timeout: 30000, // Defaults to 30s
});
client.getSigningKey(header.kid, function (err, key) {
if (err || !key || !(key.publicKey || key.rsaPublicKey)) {
console.error('User could not be resolved!');
callback(err, null);
return;
}
Expand All @@ -37,6 +37,7 @@ export class WsGuard implements CanActivate {
return new Promise(function (resolve, reject) {
jwt.verify(bearerToken, getKey, function (err, decoded) {
if (err || !decoded || !decoded['sub'] || !decoded['preferred_username']) {
console.error('User could not be resolved!');
resolve('User could not be resolved!');
return;
}
Expand Down

0 comments on commit 3a5f742

Please sign in to comment.