Skip to content

Commit

Permalink
Update server.js
Browse files Browse the repository at this point in the history
  • Loading branch information
yzFrankli committed Oct 26, 2024
1 parent 0d5f8e8 commit 3b3bfe2
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,20 @@ const Contact = mongoose.model("contact", ContactSchema)
// Contact

// TODO (Frank & Madeline): Create an endpoint to receive and upload contact inquiries to the database
app.post('/contact', async (req, res) => {
app.post('/api/contact', async (req, res) => {
const{ name, email, subject, message } = req.body
try {
const newContact = new Contact ({
name,
email,
subject,
message
await Contact.create({
name: name,
email: email,
subject: subject,
message: message
})
await newContact.save()
res.status(201).json({message: 'Inquiry submitted successfully'})
}
catch (err) {
console.error('Error saving contact data:', err);
process.exit(1);
console.error('Error submitting inquiry:', err);
res.status(500).json({message: 'Error submitting inquiry'})
}
})

Expand Down

0 comments on commit 3b3bfe2

Please sign in to comment.