diff --git a/.changeset/proud-donkeys-exercise.md b/.changeset/proud-donkeys-exercise.md new file mode 100644 index 00000000..eb55da95 --- /dev/null +++ b/.changeset/proud-donkeys-exercise.md @@ -0,0 +1,5 @@ +--- +"@zazuko/trifid-plugin-sparql-proxy": patch +--- + +Enable stream support back diff --git a/packages/sparql-proxy/index.js b/packages/sparql-proxy/index.js index d484f9c4..8778e8dd 100644 --- a/packages/sparql-proxy/index.js +++ b/packages/sparql-proxy/index.js @@ -4,7 +4,7 @@ import { Readable } from 'node:stream' import { performance } from 'node:perf_hooks' import { Worker } from 'node:worker_threads' import { sparqlGetRewriteConfiguration } from 'trifid-core' -// import replaceStream from 'string-replace-stream' +import replaceStream from 'string-replace-stream' import rdf from '@zazuko/env-node' const defaultConfiguration = { @@ -250,16 +250,17 @@ const factory = async (trifid) => { const contentType = response.headers.get('content-type') - let responseStream = await response.text() // response.body + /** @type {any} */ + let responseStream = response.body if (rewriteResponse && options.rewriteResults) { - responseStream = responseStream.replaceAll(rewriteResponse.origin, rewriteResponse.replacement) - // responseStream = Readable - // .from(responseStream) - // .pipe(replaceStream( - // rewriteResponse.origin, - // rewriteResponse.replacement, - // )) + responseStream = Readable + .from(responseStream) + .pipe(replaceStream( + rewriteResponse.origin, + rewriteResponse.replacement, + )) } + responseStream = Readable.fromWeb(responseStream) reply .status(response.status)