2020-08-24 10:43:55 +00:00
|
|
|
const fetch = require("node-fetch")
|
|
|
|
const {render} = require("pinski/plugins")
|
2020-10-18 08:51:09 +00:00
|
|
|
const {getUser} = require("../utils/getuser")
|
2020-08-24 10:43:55 +00:00
|
|
|
|
|
|
|
module.exports = [
|
|
|
|
{
|
2020-10-18 08:51:09 +00:00
|
|
|
route: "/(?:search|results)", methods: ["GET"], code: async ({req, url}) => {
|
2020-08-24 10:43:55 +00:00
|
|
|
const query = url.searchParams.get("q") || url.searchParams.get("search_query")
|
|
|
|
const fetchURL = new URL("http://localhost:3000/api/v1/search")
|
|
|
|
fetchURL.searchParams.set("q", query)
|
|
|
|
const results = await fetch(fetchURL.toString()).then(res => res.json())
|
2020-10-18 08:51:09 +00:00
|
|
|
const instanceOrigin = getUser(req).getSettingsOrDefaults().instance
|
|
|
|
return render(200, "pug/search.pug", {query, results, instanceOrigin})
|
2020-08-24 10:43:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|