Skip to content

Commit

Permalink
Deploying Nodejs on versel
Browse files Browse the repository at this point in the history
  • Loading branch information
UjjwalSaini07 committed Oct 12, 2024
1 parent 24a4d2c commit 0e4ff62
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Backend/api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// api/index.js
export default function handler(req, res) {
res.status(200).json({ message: 'API is running' });
}

46 changes: 46 additions & 0 deletions Backend/api/send-email.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const nodemailer = require('nodemailer');

export default async function handler(req, res) {
if (req.method === 'POST') {
const { email } = req.body;

if (!email) {
return res.status(400).json({ success: false, message: 'Email is required' });
}

// Set up nodemailer transporter
const transporter = nodemailer.createTransport({
service: 'gmail', // You can use another service like SendGrid or SMTP
auth: {
user: 'saini.ujjwals007@gmail.com',
pass: 'pnot bnpc cfwp wnyx',
},
});

const mailOptions = {
from: 'saini.ujjwals007@gmail.com', // Your email
to: email,
subject: 'Congratulations! You’ve Successfully Subscribed to Daily Bhagavad Gita Shlokas!',
text: `You have successfully subscribed to daily Bhagavad Gita Shlokas! Congratulations! 🎉
Get ready to dive deep into the profound wisdom and teachings of the Bhagavad Gita. Each day, you will receive a meaningful Shloka delivered straight to your inbox. These sacred verses will guide you on a spiritual journey, offering insights into life, duty, and inner peace.
Enjoy the daily dose of timeless philosophy and find inspiration from the divine teachings of Lord Krishna. 🌿
We are excited to have you with us on this path of spiritual growth!`
};

try {
const info = await transporter.sendMail(mailOptions);
console.log('Email sent:', info.response);
return res.status(200).json({ success: true, message: 'Email sent successfully!' });
} catch (error) {
console.error('Error sending email:', error);
return res.status(500).json({ success: false, message: 'Failed to send email', error });
}
} else {
// Handle other HTTP methods
res.setHeader('Allow', ['POST']);
return res.status(405).end(`Method ${req.method} Not Allowed`);
}
}
3 changes: 2 additions & 1 deletion Backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "vercel dev"
},
"author": "Ujjwal Saini",
"license": "ISC",
Expand Down
7 changes: 7 additions & 0 deletions Backend/vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"version": 2,
"builds": [
{ "src": "api/**/*.js", "use": "@vercel/node" }
]
}

0 comments on commit 0e4ff62

Please sign in to comment.