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

Use in-memory token store when developing locally #273

Merged
merged 4 commits into from
Nov 29, 2023
Merged

Conversation

marcus-bcl
Copy link
Contributor

Removes the need for a local Redis container


type RestClientBuilder<T> = (token: string) => T

export const dataAccess = () => ({
applicationInfo,
hmppsAuthClient: new HmppsAuthClient(new TokenStore(createRedisClient())),
hmppsAuthClient: new HmppsAuthClient(
config.redis.enabled ? new RedisTokenStore(createRedisClient()) : new TestingTokenStore(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth calling this InMemoryToken store?
We use an in memory token store for jobs as it means don't need to worry about redis being accessible (dodgy DNS issues)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I'll rename it

import RedisStore from 'connect-redis'
import express, { Router } from 'express'
import { createRedisClient } from '../data/redisClient'
import config from '../config'
import logger from '../../logger'

export default function setUpWebSession(): Router {
const client = createRedisClient()
client.connect().catch((err: Error) => logger.error(`Error connecting to Redis`, err))
let store: Store
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this fall back to the inmemory store? what happens if you pass undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Express defaults to a MemoryStore, so passing undefined means it uses its own in-memory store for session data.

Copy link
Contributor

@andrewrlee andrewrlee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@andrewrlee andrewrlee merged commit 3949b48 into main Nov 29, 2023
4 checks passed
@andrewrlee andrewrlee deleted the remove-redis branch November 29, 2023 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants