Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide config to switch between in-memory and redis cache. #35

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading