Skip to content

Commit

Permalink
Merge branch 'main' into translate-page
Browse files Browse the repository at this point in the history
  • Loading branch information
myix765 committed Dec 9, 2024
2 parents 1a5f9e7 + 111acf7 commit 89249a4
Show file tree
Hide file tree
Showing 16 changed files with 547 additions and 419 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ jobs:
with:
cache: "npm"
- name: Install Vercel CLI
run: npm install --global vercel@latest
run: npm install --global vercel
- name: Deploy Project Artifacts to Vercel
run: vercel deploy --token=${{ secrets.VERCEL_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ jobs:
with:
cache: "npm"
- name: Install Vercel CLI
run: npm install --global vercel@latest
run: npm install --global vercel
- name: Deploy Project Artifacts to Vercel
run: vercel deploy --prod --token=${{ secrets.VERCEL_TOKEN }}
46 changes: 41 additions & 5 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const cors = require('cors');
const mongo = require('mongodb');
const mongoose = require('mongoose');
const mongoSanitize = require('express-mongo-sanitize');
const nodemailer = require('nodemailer');

const app = express()
app.use(cors())
Expand Down Expand Up @@ -216,21 +217,56 @@ app.get('/api/users', async (req, res) => {
// Post Contact
app.post('/api/contact', async (req, res) => {
const { name, email, subject, message } = req.body

try {
const newContact = new Contact({
name,
email,
subject,
message
})
await newContact.save()
});
await newContact.save();

// Nodemailer setup
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.ADMIN_EMAIL,
pass: process.env.ADMIN_PASSWORD,
},
});

transporter.verify((error, success) => {
if (error) {
console.error('Error initializing transporter:', error);
} else {
console.log('Transporter is ready to send emails', success);
}
});


const mailOptions = {
from: email,
to: process.env.ADMIN_EMAIL,
subject: `Contact Form: ${subject}`,
html: `
<p><strong>From:</strong> ${name} (${email})</p>
<p><strong>Subject:</strong> ${subject}</p>
<p><strong>Message:</strong></p>
<p>${message}</p>
`
};

res.status(201).json({ message: 'Inquiry submitted successfully' })
// Send email
await transporter.sendMail(mailOptions);

res.status(201).json({ message: 'Inquiry and email submitted successfully' });
}
catch (err) {
res.status(500).json({ message: 'Error submitting inquiry' });
console.error('Error submitting inquiry:', err);
res.status(500).json({ message: 'Error submitting inquiry', error: err.message });
}
})
});


/* CLASS RELATED ENDPOINTS */
Expand Down
Loading

0 comments on commit 89249a4

Please sign in to comment.