Skip to content

Commit

Permalink
Update config and redis dev setup
Browse files Browse the repository at this point in the history
  • Loading branch information
snaerseljan committed Sep 23, 2024
1 parent 7b86f8e commit 9bee7c7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 29 deletions.
1 change: 1 addition & 0 deletions apps/services/bff/infra/admin-portal.infra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const serviceSetup = (): ServiceBuilder<'services-bff-admin-portal'> =>
BFF_CLIENT_KEY_PATH: '/stjornbord',
BFF_CALLBACKS_BASE_PATH: generateWebBaseUrls('/stjornbord/bff/callbacks'),
BFF_CLIENT_BASE_URL: generateWebBaseUrls(),
BFF_LOGOUT_REDIRECT_URI: generateWebBaseUrls(),
BFF_PROXY_API_ENDPOINT: generateWebBaseUrls('/api/graphql'),
BFF_ALLOWED_EXTERNAL_API_URLS: {
dev: json(['https://api.dev01.devland.is']),
Expand Down
47 changes: 31 additions & 16 deletions apps/services/bff/src/app/bff.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig } from '@island.is/nest/config'

import { z } from 'zod'
import { environment } from '../environment'
import { isProduction } from '../environment'
import { removeTrailingSlash } from '../utils/removeTrailingSlash'

export const idsSchema = z.strictObject({
Expand All @@ -12,11 +12,19 @@ export const idsSchema = z.strictObject({
})

const BffConfigSchema = z.object({
redis: z.object({
nodes: z.array(z.string()),
ssl: z.boolean(),
}),
redis: z
.object({
name: z.string(),
nodes: z.array(z.string()),
ssl: z.boolean(),
})
// Only required in production
.optional(),
graphqlApiEndpont: z.string(),
/**
* The URL to redirect to after logging out
*/
logoutRedirectUri: z.string(),
/**
* Bff client base URL
*/
Expand Down Expand Up @@ -48,25 +56,32 @@ export const BffConfig = defineConfig({
const callbacksBaseRedirectPath = removeTrailingSlash(
env.required('BFF_CALLBACKS_BASE_PATH'),
)
// Redis nodes are only required in production
// In development, we can use a local Redis server or
// rely on the default in-memory cache provided by CacheModule
const redisNodes = env.optionalJSON('BFF_REDIS_URL_NODES')

return {
parSupportEnabled: env.optionalJSON('BFF_PAR_SUPPORT_ENABLED') ?? false,
clientBaseUrl: env.required('BFF_CLIENT_BASE_URL'),
logoutRedirectUri: env.required('BFF_LOGOUT_REDIRECT_URI'),
/**
* Our main GraphQL API endpoint
*/
graphqlApiEndpont: env.required('BFF_PROXY_API_ENDPOINT'),
redis: {
nodes: env.requiredJSON('REDIS_URL_NODE_01', [
'localhost:7000',
'localhost:7001',
'localhost:7002',
'localhost:7003',
'localhost:7004',
'localhost:7005',
]),
ssl: environment.production,
},
redis: isProduction
? {
name: env.required('BFF_REDIS_NAME'),
nodes: env.requiredJSON('BFF_REDIS_URL_NODES'),
ssl: true,
}
: redisNodes
? {
name: env.optional('BFF_REDIS_NAME') ?? 'unnamed-bff',
nodes: redisNodes,
ssl: false,
}
: undefined,
ids: {
issuer: env.required('IDENTITY_SERVER_ISSUER_URL'),
clientId: env.required('IDENTITY_SERVER_CLIENT_ID'),
Expand Down
2 changes: 1 addition & 1 deletion apps/services/bff/src/app/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,6 @@ export class AuthService {
// Delete session cookie
res.clearCookie('sid')

return res.redirect(this.config.clientBaseUrl)
return res.redirect(this.config.logoutRedirectUri)
}
}
16 changes: 5 additions & 11 deletions apps/services/bff/src/app/modules/cache/cache.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,14 @@ import { CacheService } from './cache.service'
export class CacheModule {
static register(): DynamicModule {
const imports =
process.env.NODE_ENV === 'test' || process.env.INIT_SCHEMA === 'true'
process.env.NODE_ENV === 'test'
? [NestCacheModule.register()]
: [
NestCacheModule.registerAsync({
useFactory: ({
redis: { ssl, nodes },
}: ConfigType<typeof BffConfig>) => ({
store: redisInsStore(
createRedisCluster({
name: 'bff',
ssl,
nodes,
}),
),
useFactory: ({ redis }: ConfigType<typeof BffConfig>) => ({
store: redis
? redisInsStore(createRedisCluster(redis))
: undefined,
}),
inject: [BffConfig.KEY],
}),
Expand Down
2 changes: 1 addition & 1 deletion apps/services/bff/src/environment/environment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BffEnvironment, environmentSchema } from './environment.schema'

const isProduction = process.env.NODE_ENV === 'production'
export const isProduction = process.env.NODE_ENV === 'production'

const parsedEnvironment = environmentSchema.parse({
production: isProduction,
Expand Down

0 comments on commit 9bee7c7

Please sign in to comment.