fpcourse/pages/api/lesson.ts
2023-04-14 15:36:03 -05:00

15 lines
452 B
TypeScript

// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import { readFile } from "fs/promises";
import type { NextApiRequest, NextApiResponse } from "next";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const { name } = req.query;
const result = await readFile(`lessons/${name}.md`);
const resultString = result.toString();
res.status(200).json({ contents: resultString });
}