Skip to content

Commit

Permalink
enable latest component features on dev and preprod (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
whitfield-mj authored Sep 27, 2023
1 parent eac1983 commit 3409bb3
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions helm_deploy/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ generic-service:
APPOINTMENTS_URL: "https://activities-dev.prison.service.justice.gov.uk/appointments"
APPOINTMENTS_ENABLED_PRISONS: "LEI,RSI"
COMPONENT_API_URL: "https://frontend-components-dev.hmpps.service.justice.gov.uk"
COMPONENT_API_LATEST: "true"

generic-prometheus-alerts:
alertSeverity: digital-prison-service-dev
1 change: 1 addition & 0 deletions helm_deploy/values-preprod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ generic-service:
APPOINTMENTS_URL: "https://activities-preprod.prison.service.justice.gov.uk/appointments"
APPOINTMENTS_ENABLED_PRISONS: ""
COMPONENT_API_URL: "https://frontend-components-preprod.hmpps.service.justice.gov.uk"
COMPONENT_API_LATEST: "true"

allowlist:
office: "217.33.148.210/32"
Expand Down
1 change: 1 addition & 0 deletions helm_deploy/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ generic-service:
APPOINTMENTS_URL: "https://activities.prison.service.justice.gov.uk/appointments"
APPOINTMENTS_ENABLED_PRISONS: ""
COMPONENT_API_URL: "https://frontend-components.hmpps.service.justice.gov.uk"
COMPONENT_API_LATEST: "false"

allowlist:
office: "217.33.148.210/32"
Expand Down
1 change: 1 addition & 0 deletions server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export default {
deadline: Number(get('COMPONENT_API_TIMEOUT_SECONDS', 20000)),
},
agent: new AgentConfig(Number(get('COMPONENT_API_TIMEOUT_SECONDS', 20000))),
latest: get('COMPONENT_API_LATEST', 'false') === 'true',
},
},
serviceUrls: {
Expand Down
4 changes: 3 additions & 1 deletion server/data/componentApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ export default class ComponentApiRestClient implements ComponentApiClient {
getComponents<T extends AvailableComponent[]>(
components: T,
userToken: string,
useLatest: boolean,
): Promise<Record<T[number], Component>> {
const useLatestHeader = useLatest ? { 'x-use-latest-features': 'true' } : {}
return this.restClient.get<Record<T[number], Component>>({
path: `/components`,
query: `component=${components.join('&component=')}`,
headers: { 'x-user-token': userToken },
headers: { 'x-user-token': userToken, ...useLatestHeader },
})
}
}
6 changes: 5 additions & 1 deletion server/data/interfaces/componentApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@ import Component from './component'
import AvailableComponent from './AvailableComponent'

export interface ComponentApiClient {
getComponents<T extends AvailableComponent[]>(component: T, userToken: string): Promise<Record<T[number], Component>>
getComponents<T extends AvailableComponent[]>(
component: T,
userToken: string,
useLatest: boolean,
): Promise<Record<T[number], Component>>
}
8 changes: 6 additions & 2 deletions server/middleware/frontEndComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import type { RequestHandler } from 'express'
import logger from '../../logger'
import { Services } from '../services'

export default function getFrontendComponents({ componentService }: Services): RequestHandler {
export default function getFrontendComponents({ componentService }: Services, useLatest: boolean): RequestHandler {
return async (req, res, next) => {
try {
const { header, footer } = await componentService.getComponents(['header', 'footer'], res.locals.user.token)
const { header, footer } = await componentService.getComponents(
['header', 'footer'],
res.locals.user.token,
useLatest,
)

res.locals.feComponents = {
header: header.html,
Expand Down
2 changes: 1 addition & 1 deletion server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function routes(services: Services): Router {

commonRoutes()

get('/prisoner/*', getFrontendComponents(services))
get('/prisoner/*', getFrontendComponents(services, config.apis.frontendComponents.latest))

get('/prisoner/:prisonerNumber', getPrisonerData(services), checkPrisonerInCaseload(), async (req, res, next) => {
const prisonerData = req.middleware?.prisonerData
Expand Down
3 changes: 2 additions & 1 deletion server/services/componentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export default class ComponentService {
async getComponents<T extends AvailableComponent[]>(
components: T,
userToken: string,
useLatest = false,
): Promise<Record<T[number], Component>> {
return this.componentApiClientBuilder(userToken).getComponents(components, userToken)
return this.componentApiClientBuilder(userToken).getComponents(components, userToken, useLatest)
}
}
2 changes: 1 addition & 1 deletion server/views/partials/layout.njk
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
crossorigin
/>

{% if feComponents.jsInclude %}
{% if feComponents.jsIncludes %}
{% for js in feComponents.jsIncludes %}
<script src="{{ js }}" nonce="{{ cspNonce }}"></script>
{% endfor %}
Expand Down

0 comments on commit 3409bb3

Please sign in to comment.