Skip to content

Commit

Permalink
Tester ut readable-web-to-node-stream
Browse files Browse the repository at this point in the history
  • Loading branch information
nattaphongklinjan committed Nov 6, 2024
1 parent 8412f16 commit 9cf12c4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
29 changes: 29 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"prop-types": "^15.8.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"readable-web-to-node-stream": "^3.0.2",
"swr": "^2.2.5",
"unleash-client": "^5.6.1",
"uuid": "^10.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { logger } from "@navikt/next-logger";
import { ReadableWebToNodeStream } from "readable-web-to-node-stream";
import { v4 as uuidv4 } from "uuid";
import { getSession } from "../../../../../lib/auth.utils";
import { Readable } from "stream";

const audience = `${process.env.SAF_SELVBETJENING_CLUSTER}:teamdokumenthandtering:${process.env.SAF_SELVBETJENING_SCOPE}`;

Expand Down Expand Up @@ -29,18 +29,8 @@ const handleHentDokument = async (req, res) => {

try {
const response = await fetch(requestUrl, requestHeaders);

// @ts-ignore // Ignorer respons.body
const stream = Readable.fromWeb(response.body);

stream.pipe(res);
stream.on("error", (err) => {
res.status(500).send(`Feil ved streaming av SAF dokument: ${err}`);
});

stream.on("end", () => {
res.end();
});
const readableWebStream = response.body;
return new ReadableWebToNodeStream(readableWebStream);
} catch (errors) {
logger.error(`Feil fra SAF med call-id ${callId}: ${errors}`);
return res.status(500).send(errors);
Expand Down

0 comments on commit 9cf12c4

Please sign in to comment.