feat: init
This commit is contained in:
23
routes/api/recipes/[name].ts
Normal file
23
routes/api/recipes/[name].ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { HandlerContext } from "$fresh/server.ts";
|
||||
import { getDocument } from "../../../lib/documents.ts";
|
||||
import { parseRecipe } from "../../../lib/recipes.ts";
|
||||
|
||||
export async function getRecipe(name: string) {
|
||||
const document = await getDocument(`Recipes/${name}.md`);
|
||||
|
||||
const recipe = parseRecipe(document, name);
|
||||
|
||||
return recipe;
|
||||
}
|
||||
|
||||
export const handler = async (
|
||||
_req: Request,
|
||||
_ctx: HandlerContext,
|
||||
): Promise<Response> => {
|
||||
const recipe = await getRecipe(_ctx.params.name);
|
||||
|
||||
const headers = new Headers();
|
||||
headers.append("Content-Type", "application/json");
|
||||
|
||||
return new Response(JSON.stringify(recipe));
|
||||
};
|
Reference in New Issue
Block a user