From 8ae263f88bfdc971ed0566362340fcfaffb0c703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halvor=20Grizzly=20Bj=C3=B8rn?= Date: Thu, 14 Dec 2023 11:28:12 +0100 Subject: [PATCH] :alien: Tester ut proxying av kall med next-api-proxy --- pages/api/innsending/vedlegg/les.ts | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/pages/api/innsending/vedlegg/les.ts b/pages/api/innsending/vedlegg/les.ts index f35c3f33..94477a57 100644 --- a/pages/api/innsending/vedlegg/les.ts +++ b/pages/api/innsending/vedlegg/les.ts @@ -1,26 +1,35 @@ import { getStringFromPossiblyArrayQuery } from '@navikt/aap-felles-utils-client'; -import { beskyttetApi, getAccessTokenFromRequest, tokenXApiProxy } from '@navikt/aap-felles-utils'; +import { beskyttetApi, getAccessTokenFromRequest, getTokenX } from '@navikt/aap-felles-utils'; +import { proxyApiRouteRequest } from '@navikt/next-api-proxy'; const handler = beskyttetApi(async (req, res) => { const uuid = getStringFromPossiblyArrayQuery(req.query.uuid); if (!uuid) { res.status(400).json({ error: 'uuid må være en string' }); } - const accessToken = getAccessTokenFromRequest(req); - return await tokenXApiProxy({ - url: `${process.env.INNSENDING_URL}/mellomlagring/fil/${uuid}`, - method: 'GET', - prometheusPath: '/mellomlagring/fil', + + const accessToken = getAccessTokenFromRequest(req)?.substring('Bearer '.length)!; + let tokenxToken; + try { + tokenxToken = await getTokenX(accessToken, process.env.INNSENDING_AUDIENCE!); + } catch (err: any) { + console.log('getTokenXError', err); + } + return await proxyApiRouteRequest({ + hostname: 'innsending', + path: `mellomlagring/fil/${uuid}`, req: req, - audience: process.env.INNSENDING_AUDIENCE!, - bearerToken: accessToken, - rawResonse: true, + /* @ts-ignore: TODO */ + res: res, + bearerToken: tokenxToken, }); }); export const config = { api: { responseLimit: '50mb', + bodyParser: false, + externalResolver: true, }, };