diff --git a/app/src/search.js b/app/src/search.js index 598ab89..58d8e15 100644 --- a/app/src/search.js +++ b/app/src/search.js @@ -1,5 +1,4 @@ // TODO: unit tests for business logic -// TODO: export in JSON const cheerio = require("cheerio"); @@ -35,7 +34,7 @@ async function handleSearch(req, res) { format: "json" }); - const response = await fetch( + const reposnse = await fetch( `${searxngUrl}/search?${params}`, { headers: { @@ -43,9 +42,18 @@ async function handleSearch(req, res) { } } ); + const data = await reposnse.json(); - const data = await response.json(); - res.json(filterJson(data.results || [])); + const filteredresults = filterJson(data.results || []); + + // Send the result as a downloadable JSON file + res.setHeader("Content-Type", "application/json; charset=utf-8"); + res.setHeader( + "Content-Disposition", + 'attachment; filename="output.json"' + ); + + return res.send(JSON.stringify(filteredresults, null, 2)); } catch (error) { console.error("[SEARCH.JS] " + error); res.status(500).send("

Search failed!
See the console for the error.

");