mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-16 09:11:38 +00:00
21 lines
491 B
TypeScript
21 lines
491 B
TypeScript
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
import { Post } from 'types';
|
|
import { postLists } from 'lib/posts';
|
|
|
|
export default async function handler(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse<Post[]>
|
|
) {
|
|
const getPosts = async () => {
|
|
const posts = await postLists();
|
|
res.status(200).json(posts);
|
|
};
|
|
|
|
switch (req.method) {
|
|
case 'GET':
|
|
return getPosts();
|
|
default:
|
|
return res.status(405).end(`Method ${req.method} Not Allowed`);
|
|
}
|
|
}
|