Loading
- Failed: {{ error }}
+ Failed: {{ error.statusMessage }}
diff --git a/server/api/recipes.get.ts b/server/api/recipes.get.ts
index 9059765..fb80e2d 100644
--- a/server/api/recipes.get.ts
+++ b/server/api/recipes.get.ts
@@ -1,9 +1,10 @@
import { parseRecipeData } from "~/utils/recipes";
+import type { Meal } from "~/types/recipe";
export default defineEventHandler(async (_event) => {
const { apiUrl } = useRuntimeConfig();
- const data = await $fetch<{ meals: unknown }>(
+ const data = await $fetch<{ meals: Meal[] }>(
new URL("random.php", apiUrl).toString(),
);
diff --git a/server/api/recipes/[id].get.ts b/server/api/recipes/[id].get.ts
new file mode 100644
index 0000000..4f8f61c
--- /dev/null
+++ b/server/api/recipes/[id].get.ts
@@ -0,0 +1,20 @@
+import { parseRecipeData } from "~/utils/recipes";
+import type { Meal } from "~/types/recipe";
+
+export default defineEventHandler(async (event) => {
+ const { apiUrl } = useRuntimeConfig();
+ const id = getRouterParam(event, "id");
+
+ const data = await $fetch<{ meals: Meal[] }>(
+ new URL(`lookup.php?i=${id}`, apiUrl).toString(),
+ );
+ if (!data?.meals) {
+ throw createError({
+ statusCode: 404,
+ statusMessage: "Recipe not found",
+ });
+ }
+
+ const recipes = parseRecipeData(data);
+ return recipes[0];
+});
diff --git a/types/recipe.ts b/types/recipe.ts
index 5683d31..1f0911f 100644
--- a/types/recipe.ts
+++ b/types/recipe.ts
@@ -1,6 +1,7 @@
import { z } from "zod";
export type Recipe = {
+ id: string;
title: string;
pictureUrl: string;
videoUrl: string;
diff --git a/utils/recipes.ts b/utils/recipes.ts
index 76ff094..db9f2ed 100644
--- a/utils/recipes.ts
+++ b/utils/recipes.ts
@@ -17,6 +17,7 @@ export function parseRecipeData(data: ApiResponse): Recipe[] {
}
return {
+ id: meal.idMeal,
title: meal.strMeal,
pictureUrl: meal.strMealThumb,
videoUrl: meal.strYoutube,