1
0
mirror of https://git.sr.ht/~cadence/cloudtube synced 2024-12-22 13:07:00 +00:00

Use preferred instance for search

This commit is contained in:
Cadence Ember 2021-01-01 17:15:02 +13:00
parent 0497bba505
commit 0da13ac0e6
No known key found for this signature in database
GPG Key ID: BC1C2C61CF521B17

View File

@ -6,10 +6,10 @@ module.exports = [
{
route: "/(?:search|results)", methods: ["GET"], code: async ({req, url}) => {
const query = url.searchParams.get("q") || url.searchParams.get("search_query")
const fetchURL = new URL("http://localhost:3000/api/v1/search")
const instanceOrigin = getUser(req).getSettingsOrDefaults().instance
const fetchURL = new URL(`${instanceOrigin}/api/v1/search`)
fetchURL.searchParams.set("q", query)
const results = await fetch(fetchURL.toString()).then(res => res.json())
const instanceOrigin = getUser(req).getSettingsOrDefaults().instance
return render(200, "pug/search.pug", {query, results, instanceOrigin})
}
}