24 lines
609 B
TypeScript
24 lines
609 B
TypeScript
import { HandlerContext } from "$fresh/server.ts";
|
|
import { getDocument } from "@lib/documents.ts";
|
|
import { parseMovie } from "@lib/movies.ts";
|
|
|
|
export async function getMovie(name: string) {
|
|
const document = await getDocument(`Media/movies/${name}.md`);
|
|
|
|
const movie = parseMovie(document, name);
|
|
|
|
return movie;
|
|
}
|
|
|
|
export const handler = async (
|
|
_req: Request,
|
|
_ctx: HandlerContext,
|
|
): Promise<Response> => {
|
|
const movie = await getMovie(_ctx.params.name);
|
|
|
|
const headers = new Headers();
|
|
headers.append("Content-Type", "application/json");
|
|
|
|
return new Response(JSON.stringify(movie));
|
|
};
|