Files
datamining_881/frontend/app/api/search/route.ts
Vadella, Anna 3a912bf09e Frontend changes
I still need to change the path of the excel in convert_to_JSON.js to be the updated data xlsx lmao
2026-03-26 12:35:58 -04:00

14 lines
874 B
TypeScript

import movies from "../../../../movies.json"; // import JSON dataset containing all movies
export async function GET(req: Request) {
const {searchParams} = new URL(req.url); // gets request URL w/ query parameters
const query = searchParams.get("q")?.toLowerCase() || "";
const results = movies // only return movies that include search term in their title
.filter((m) => m.title.toLowerCase().includes(query)) // filter searches dataset for titles containing query
.slice(0, 10); // limit to top 10 results
return new Response(JSON.stringify(results), {
headers: {"Content-Type": "application/json"}, // returns JSON array of movie objects
});
}