Skip to content

Commit

Permalink
chore: conditional for auth enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
8lane committed Jan 23, 2025
1 parent d37d195 commit 284c22e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/api/utils/api.utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UKHSA_SWITCHBOARD_COOKIE_NAME } from '@/app/constants/app.constants'
import { isSSR, isWellKnownEnvironment } from '@/app/utils/app.utils'
import { cacheRevalidationInterval } from '@/config/constants'
import { authEnabled, cacheRevalidationInterval } from '@/config/constants'

import { getApiBaseUrl } from '../requests/helpers'

Expand Down Expand Up @@ -43,7 +43,8 @@ export async function client<T>(
body: body ? JSON.stringify(body) : undefined,
...customConfig,
next: {

Check failure on line 45 in src/api/utils/api.utils.ts

View workflow job for this annotation

GitHub Actions / Playwright tests (1/3)

Object literal may only specify known properties, and 'next' does not exist in type 'RequestInit'.

Check failure on line 45 in src/api/utils/api.utils.ts

View workflow job for this annotation

GitHub Actions / Playwright tests (2/3)

Object literal may only specify known properties, and 'next' does not exist in type 'RequestInit'.

Check failure on line 45 in src/api/utils/api.utils.ts

View workflow job for this annotation

GitHub Actions / Lighthouse

Object literal may only specify known properties, and 'next' does not exist in type 'RequestInit'.

Check failure on line 45 in src/api/utils/api.utils.ts

View workflow job for this annotation

GitHub Actions / Playwright tests (3/3)

Object literal may only specify known properties, and 'next' does not exist in type 'RequestInit'.
revalidate: customConfig.next?.revalidate ?? cacheRevalidationInterval,
// The public dashboard is behind a CDN so doesn't rely on any Next.js caching
revalidate: authEnabled ? customConfig.next?.revalidate ?? cacheRevalidationInterval : 0,
},
headers: {
...headers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import { HealthAlertTypes } from '@/api/models/Alerts'
import { PageType } from '@/api/requests/cms/getPages'
import { getPageBySlug } from '@/api/requests/getPageBySlug'
import { RelatedLinksWrapper } from '@/app/components/ui/ukhsa/RelatedLinks/RelatedLinksWrapper'
import { authEnabled } from '@/config/constants'

import AlertBody from './AlertBody'

export const dynamic = authEnabled ? 'auto' : 'force-dynamic'

export async function generateMetadata({ params: { region } }: { params: { region: string } }): Promise<Metadata> {
return {
title: `Weather alert for ${region} | UKHSA data dashboard`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import { List } from '@/app/components/ui/ukhsa/List/List'
import { ListItem } from '@/app/components/ui/ukhsa/List/ListItem'
import { RelatedLinksWrapper } from '@/app/components/ui/ukhsa/RelatedLinks/RelatedLinksWrapper'
import { renderCompositeBlock } from '@/app/utils/cms.utils'
import { authEnabled } from '@/config/constants'

import AlertList from './AlertList'

export const dynamic = authEnabled ? 'auto' : 'force-dynamic'

export async function generateMetadata({ params: { weather } }: { params: { weather: string } }): Promise<Metadata> {
const {
meta: { seo_title: title, search_description: description },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { ListItem } from '@/app/components/ui/ukhsa/List/ListItem'
import { ListItemArrow, ListItemArrowLink, ListItemArrowParagraph } from '@/app/components/ui/ukhsa/List/ListItemArrow'
import { RelatedLinksWrapper } from '@/app/components/ui/ukhsa/RelatedLinks/RelatedLinksWrapper'
import { renderCompositeBlock } from '@/app/utils/cms.utils'
import { authEnabled } from '@/config/constants'

export const dynamic = authEnabled ? 'auto' : 'force-dynamic'

export async function generateMetadata() {
const {
Expand Down
3 changes: 3 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Trans } from 'react-i18next/TransWithoutContext'

import { AWSRum } from '@/app/components/ui/ukhsa/Scripts/AWSRum/AWSRum'
import { getServerTranslation } from '@/app/i18n'
import { authEnabled } from '@/config/constants'

import { Footer } from './components/ui/govuk'
import { CookieBanner } from './components/ui/ukhsa'
Expand All @@ -19,6 +20,8 @@ import { GovUK } from './components/ui/ukhsa/Scripts/GovUK/GovUK'
import { UKHSA_GDPR_COOKIE_NAME } from './constants/cookies.constants'
import { Providers } from './providers'

export const dynamic = authEnabled ? 'auto' : 'force-dynamic'

export default async function RootLayout({ children }: { children: React.ReactNode }) {
const { t } = await getServerTranslation('common')

Expand Down
3 changes: 3 additions & 0 deletions src/app/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import { MetadataRoute } from 'next'

import { getPages, PageType } from '@/api/requests/cms/getPages'
import { getHealthAlerts } from '@/api/requests/health-alerts/getHealthAlerts'
import { authEnabled } from '@/config/constants'
import { logger } from '@/lib/logger'

import { getSiteUrl, toSlug } from './utils/app.utils'

export const dynamic = authEnabled ? 'auto' : 'force-dynamic'

export const changeFrequencyMap: Record<number, MetadataRoute.Sitemap[number]['changeFrequency']> = {
1: 'always',
2: 'hourly',
Expand Down
5 changes: 5 additions & 0 deletions src/config/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Checks to see if running the Authenticated version of the data dashboard
*/
export const authEnabled = process.env.AUTH_ENABLED === 'true'

/**
* The default cache revalidation interval (10 minutes)
* Can be overridden per request
Expand Down

0 comments on commit 284c22e

Please sign in to comment.