8 lines
425 B
TypeScript
8 lines
425 B
TypeScript
import type { NextApiRequest,NextApiResponse } from "next";
|
|
import { createPost,postInput } from "@/lib/write";
|
|
import { sameOrigin,apiError } from "@/lib/api";
|
|
export default async function handler(req:NextApiRequest,res:NextApiResponse){
|
|
if(req.method!=='POST')return res.status(405).end();
|
|
try{sameOrigin(req);return res.status(201).json(await createPost(postInput.parse(req.body)));}catch(e){return apiError(res,e);}
|
|
}
|