import { NextApiRequest, NextApiResponse } from "next"; import dbConnect from "../config/dbConfig"; import { createMessage, getMessages } from "../controllers/messages"; export default async function hundler(req: NextApiRequest, res: NextApiResponse) { const {method}=req switch (method) { case "GET": await dbConnect() getMessages(req, res) break; case "POST": await dbConnect() createMessage(req, res) break; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter