CoastalCommitsPastes/client/pages/api/welcome.ts

30 lines
703 B
TypeScript
Raw Normal View History

2022-11-09 21:38:05 -05:00
// a nextjs api handerl
import config from "@lib/config"
2022-11-10 02:11:36 -05:00
import renderMarkdown from "@lib/render-markdown"
2022-11-09 21:38:05 -05:00
import { NextApiRequest, NextApiResponse } from "next"
export const getWelcomeContent = async () => {
const introContent = config.welcome_content
const introTitle = config.welcome_title
2022-11-10 02:11:36 -05:00
2022-11-09 21:38:05 -05:00
return {
title: introTitle,
content: introContent,
2022-11-10 02:11:36 -05:00
rendered: renderMarkdown(introContent)
2022-11-09 21:38:05 -05:00
}
}
export default async function handler(
2022-11-10 02:11:36 -05:00
_: NextApiRequest,
2022-11-09 21:38:05 -05:00
res: NextApiResponse
) {
const welcomeContent = await getWelcomeContent()
if (!welcomeContent) {
return res.status(500).json({ error: "Missing welcome content" })
}
2022-11-10 02:11:36 -05:00
console.log(welcomeContent.title)
2022-11-09 21:38:05 -05:00
return res.json(welcomeContent)
}