Skip to content

Commit

Permalink
chore(refresh): common function for fetching backend url (#1526)
Browse files Browse the repository at this point in the history
  • Loading branch information
lindtvedtsebastian committed May 28, 2024
1 parent 5e0233e commit 597ded1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@
import { hasBoardEditorAccess } from 'app/(admin)/utils/firebase'
import { redirect } from 'next/navigation'
import { TBoard } from 'types/settings'
import { getBackendUrl } from 'utils/index'

export async function refreshBoard(board: TBoard) {
const access = await hasBoardEditorAccess(board.id)
if (!access) return redirect('/')

const res = await fetch(
`${process.env.BACKEND_SERVICE_HOST}/refresh/${board.id}`,
{
method: 'POST',
body: JSON.stringify(board),
headers: {
Authorization: `Bearer ${process.env.BACKEND_API_KEY}`,
'Content-Type': 'application/json',
},
const res = await fetch(`${getBackendUrl()}/refresh/${board.id}`, {
method: 'POST',
body: JSON.stringify(board),
headers: {
Authorization: `Bearer ${process.env.BACKEND_API_KEY}`,
'Content-Type': 'application/json',
},
)
})
return res.ok
}
8 changes: 2 additions & 6 deletions next-tavla/pages/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from 'Board/scenarios/Board/firebase'
import { Footer } from 'components/Footer'
import { useRefresh } from 'hooks/useRefresh'
import { getBackendUrl } from 'utils/index'

export async function getServerSideProps({
params,
Expand All @@ -23,16 +24,11 @@ export async function getServerSideProps({
}
}

const backend_url =
process.env.KUB_ENV === 'prd'
? 'https://tavla-api.entur.no'
: 'https://tavla-api.dev.entur.no'

return {
props: {
board,
organization: await getOrganizationWithBoard(id),
backend_url,
backend_url: getBackendUrl(),
},
}
}
Expand Down
5 changes: 5 additions & 0 deletions next-tavla/src/Shared/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function getBackendUrl() {
return process.env.KUB_ENV === 'prd'
? 'https://tavla-api.entur.no'
: 'https://tavla-api.dev.entur.no'
}

0 comments on commit 597ded1

Please sign in to comment.