Skip to content

Commit

Permalink
👽 Tester ut proxying av kall med next-api-proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbjoern committed Dec 14, 2023
1 parent 51e24da commit 8ae263f
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions pages/api/innsending/vedlegg/les.ts
Original file line number Diff line number Diff line change
@@ -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,
},
};

Expand Down

0 comments on commit 8ae263f

Please sign in to comment.