20 lines
584 B
TypeScript
20 lines
584 B
TypeScript
const url = `${process.env.OMDB_URL}?apikey=${process.env.API_KEY}`;
|
|
|
|
export const queryOMDb = async (queryParamString: string) => {
|
|
"use server";
|
|
try {
|
|
// await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
|
|
const queryUrl = `${url}&${queryParamString}`;
|
|
const response = await fetch(queryUrl);
|
|
if (!response.ok) {
|
|
throw new Error("Failed to fetch movie data");
|
|
}
|
|
const result = await response.json();
|
|
// console.log(queryUrl, result);
|
|
return result;
|
|
} catch (e) {
|
|
throw new Error("Something went wrong searching OMDb");
|
|
}
|
|
};
|