Error 504
Answered
Broad-snouted Caiman posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Broad-snouted CaimanOP
not sure why there are any errors because my application, when run locally, doesnt have any errors. this only happes when i deploy it to vercel.
this is the relevant part of the code:
api/contact - route.js
contactform.jsx -
this is the relevant part of the code:
api/contact - route.js
import connectDB from "@/app/lib/mongodb";
import Contact from "@/app/models/contact";
import { NextResponse } from "next/server";
import mongoose from "mongoose";
export async function POST(req) {
const { fullname, message } = await req.json();
try {
await connectDB();
await Contact.create({ fullname, email, message });
return NextResponse.json({
msg: ["Message sent successfully"],
success: true,
});
} catch (error) {
if (error instanceof mongoose.Error.ValidationError) {
let errorList = [];
for (let e in error.errors) {
errorList.push(error.errors[e].message);
}
console.log(errorList);
return NextResponse.json({ msg: errorList });
} else {
return NextResponse.json({ msg: ["Unable to send message."] });
}
}
}
contactform.jsx -
"use client";
import { useState } from "react";
export default function ContactForm() {
const [fullname, setFullname] = useState("");
const [message, setMessage] = useState("");
const [error, setError] = useState([]);
const [success, setSuccess] = useState(false);
const handleSubmit = async (e) => {
e.preventDefault();
const res = await fetch("api/contact", {
method: "POST",
headers: {
"Content-type": "application/json",
},
body: JSON.stringify({
fullname,
message,
}),
});
const { msg, success } = await res.json();
setError(msg);
setSuccess(success);
if (success) {
setFullname("");
setMessage("");
}
};
return(*the form*)
![Image](https://cdn.discordapp.com/attachments/1207297888494034956/1207297889102077972/image.png?ex=65df22c7&is=65ccadc7&hm=366195284d163580c3e21fee369925fd55d37e01e26e86fd72cdf3808f7ef257&)
Answered by Kokoni
Your function might have timed out because of your connectDB function not connecting to your database.
8 Replies
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Kokoni
Your function might have timed out because of your connectDB function not connecting to your database.
Answer
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Broad-snouted CaimanOP
yep i fixed it. i forgot to allow the ip address 🤦â€â™‚ï¸
Mark Solution
/Mark Solution
how do i do thattt
![Avatar](https://cdn.discordapp.com/avatars/227874586312704000/8b08fc3388d22e2ce6b4fa0b1f60f6ad.webp?size=256)
josh
right click then
![Image](https://cdn.discordapp.com/attachments/1207297888494034956/1207676656987406376/image.png?ex=65e08388&is=65ce0e88&hm=e1acb0f266c35a7413685098cfde36d3a7d271691f6e49d3092cb238d7717b53&)
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Kokoni
@Broad-snouted Caiman ^
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Broad-snouted CaimanOP
o thanks