1 year ago
#389161

Ryan Speciale
Serverless functions on Vercel not writing to database with prisma
Hello I am new to the whole serverless concept, I created my own wedding site because I'm hard headed and thought that I could create a better one then the free one offered by the knot. So I used Next.js for this project and created a form for people to RSVP. This form then posts react state objects to the API route 'api/rsvp' where I have a function to write the data to a planetscale MySql database. This function works perfectly fine locally but when I deployed the project to Vercel it no longer saved the data to the database.
Here is my API route code, am I doing anything wrong?
import prisma from '../../lib/prisma';
import type { NextApiRequest, NextApiResponse } from 'next'
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const { first, last, attending, email, meal, kids } = req.body;
if (req.method == 'POST') {
try {
const createGuest = await prisma.guest.create({
data: {
first: first,
last: last,
attending: attending,
email: email,
meal: meal,
kids: kids
}
})
res.status(202).json({ success: createGuest})
} catch(error) {
res.status(403).json({ dberror: error})
}
} else {
res.status(404)
}
}
reactjs
next.js
serverless
prisma
vercel
0 Answers
Your Answer