fpcourse/pages/api/lesson.ts

16 lines
452 B
TypeScript
Raw Normal View History

2023-04-14 20:36:03 +00:00
// 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 });
}