-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Øivind Stensrud <oivind.stensrud@nav.no> Co-authored-by: Tor Idland <tor.idland@nav.no>
- Loading branch information
1 parent
68e9fb8
commit 521a7f6
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
import { getAccessTokenFromRequest } from 'auth/accessToken'; | ||
import { beskyttetApi } from 'auth/beskyttetApi'; | ||
import { logger, tokenXApiProxy } from '@navikt/aap-felles-utils'; | ||
import { isMock } from 'utils/environments'; | ||
import metrics from 'utils/metrics'; | ||
|
||
interface KontaktInformasjon { | ||
epost?: string; | ||
mobil?: string; | ||
} | ||
|
||
const handler = beskyttetApi(async (req: NextApiRequest, res: NextApiResponse) => { | ||
const accessToken = getAccessTokenFromRequest(req); | ||
res.status(200).json(await getKrr(accessToken)); | ||
}); | ||
|
||
export const getKrr = async (accessToken?: string): Promise<KontaktInformasjon> => { | ||
if (isMock()) return { epost: 'hello@pello.no', mobil: '12345678' }; | ||
const kontaktinformasjon = await tokenXApiProxy({ | ||
url: `${process.env.OPPSLAG_URL}/krr`, | ||
prometheusPath: 'oppslag/krr', | ||
method: 'GET', | ||
audience: process.env.OPPSLAG_AUDIENCE!, | ||
bearerToken: accessToken, | ||
metricsStatusCodeCounter: metrics.backendApiStatusCodeCounter, | ||
metricsTimer: metrics.backendApiDurationHistogram, | ||
logger: logger, | ||
}); | ||
|
||
return kontaktinformasjon; | ||
}; | ||
|
||
export default handler; |