1
0
mirror of https://git.sr.ht/~cadence/cloudtube synced 2024-11-10 02:27:29 +00:00
cloudtube/api/search.js

15 lines
511 B
JavaScript
Raw Normal View History

2020-08-24 10:43:55 +00:00
const fetch = require("node-fetch")
const {render} = require("pinski/plugins")
module.exports = [
{
route: "/(?:search|results)", methods: ["GET"], code: async ({url}) => {
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-08-24 13:49:15 +00:00
return render(200, "pug/search.pug", {query, results})
2020-08-24 10:43:55 +00:00
}
}
]