diff --git "a/src/__tests__/api/dokumenter/__snapshots__/forh\303\245ndsvisning.test.ts.snap" "b/src/__tests__/api/dokumenter/__snapshots__/forh\303\245ndsvisning.test.ts.snap" index 90240504..9c6d61e3 100644 --- "a/src/__tests__/api/dokumenter/__snapshots__/forh\303\245ndsvisning.test.ts.snap" +++ "b/src/__tests__/api/dokumenter/__snapshots__/forh\303\245ndsvisning.test.ts.snap" @@ -1,3 +1,15 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`/api/dokumenter/[journalpostId]/[dokumentId]/forhandsvisning svarer med en liste dokumenter 1`] = `""`; +exports[`/api/dokumenter/[journalpostId]/[dokumentId]/forhandsvisning svarer med en liste dokumenter 1`] = ` +Object { + "data": Array [ + 98, + 105, + 110, + 195, + 166, + 114, + ], + "type": "Buffer", +} +`; diff --git a/src/pages/api/dokumenter/[journalpostId]/[dokumentId]/forhandsvisning.ts b/src/pages/api/dokumenter/[journalpostId]/[dokumentId]/forhandsvisning.ts index 44b98699..f1e2dc87 100644 --- a/src/pages/api/dokumenter/[journalpostId]/[dokumentId]/forhandsvisning.ts +++ b/src/pages/api/dokumenter/[journalpostId]/[dokumentId]/forhandsvisning.ts @@ -2,7 +2,6 @@ import { NextApiHandler } from "next"; import { v4 as uuidv4 } from "uuid"; import { withSentry } from "@sentry/nextjs"; import { getSession } from "../../../../../lib/auth.utils"; -import { Readable, Stream } from "stream"; import { logger } from "@navikt/next-logger"; const audience = `${process.env.SAF_SELVBETJENING_CLUSTER}:teamdokumenthandtering:${process.env.SAF_SELVBETJENING_SCOPE}`; @@ -30,7 +29,7 @@ async function hentDokument( return fetch(endpoint, { headers }); } -export const handleHentDokument: NextApiHandler = async (req, res) => { +export const handleHentDokument: NextApiHandler = async (req, res) => { const session = await getSession(req); if (!session.token) return res.status(401).end(); @@ -56,12 +55,8 @@ export const handleHentDokument: NextApiHandler = async (req, res) => { // Senere kan vi teste ut https://www.npmjs.com/package/readable-web-to-node-stream const arrayBuffer = await dokumentResponse.arrayBuffer(); const buffer = Buffer.from(arrayBuffer); - const readable = new Readable(); - readable._read = () => {}; // _read is required but you can noop it - readable.push(buffer); - readable.push(null); - readable.pipe(res); + return res.status(dokumentResponse.status).send(buffer); }) .catch((errors) => { console.log(errors);