Skip to content

Commit ff03596

Browse files
Merge branch 'CodeHarborHub:main' into main
2 parents 7fb981f + 424b4d3 commit ff03596

25 files changed

+3556
-13
lines changed

.anima/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

backend/.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SERVICE=gmail
2+
HOST=smtp.gmail.com
3+
PORT=587
4+
USER_MAIL_ADDRESSS='YOUR_MAIL_ADDRESS'
5+
PASS="GOOGLE APP_PASSWORD"

backend/.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Dependencies
2+
/node_modules
3+
4+
# Production
5+
/build
6+
7+
# Generated files
8+
.docusaurus
9+
.cache-loader
10+
11+
# Misc
12+
.DS_Store
13+
.env
14+
.env.local
15+
.env.development.local
16+
.env.test.local
17+
.env.production.local
18+
19+
npm-debug.log*
20+
yarn-debug.log*
21+
yarn-error.log*

backend/index.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const express = require('express');
2+
const app = express();
3+
const mailing = require('./mail/mail.js');
4+
const cors = require('cors');
5+
6+
// CORS options
7+
const corsOptions = {
8+
origin: 'https://codeharborhub.github.io', // Allow requests from this origin
9+
methods: ['GET', 'POST'], // Allow only GET and POST requests
10+
allowedHeaders: ['Content-Type'], // Allow only headers with Content-Type
11+
optionsSuccessStatus: 200,
12+
};
13+
14+
// Middleware
15+
app.use(cors(corsOptions));
16+
app.use(express.json());
17+
app.use(express.urlencoded({ extended: true }));
18+
19+
// Routes
20+
app.get("/", (req, res) => {
21+
res.send("This is Counsellor web personal use only.");
22+
});
23+
24+
app.post("/contact", async (req, res) => {
25+
try {
26+
const { name, email, feedback } = req.body;
27+
28+
if (!name || !email || !feedback) {
29+
return res.status(400).json({ ok: false, text: "Missing required fields" });
30+
}
31+
32+
const result = await mailing(name, email, feedback);
33+
34+
if (result) {
35+
res.json({ ok: true, text: "Message sent successfully" });
36+
} else {
37+
res.status(500).json({ ok: false, text: "Error sending message" });
38+
}
39+
} catch (error) {
40+
console.error("Error handling /contact request:", error);
41+
res.status(500).json({ ok: false, text: "Internal server error" });
42+
}
43+
});
44+
45+
// Start server
46+
const PORT = process.env.PORT || 5000;
47+
app.listen(PORT, () => console.log(`Server is running on port ${PORT}`));

backend/mail/mail.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const nodeMailer = require('nodemailer');
2+
const dotenv = require('dotenv');
3+
dotenv.config();
4+
5+
const mailing = async (name, userMail, message) => {
6+
const HTML = `<!DOCTYPE html>
7+
<html lang="en">
8+
<head>
9+
<meta charset="UTF-8">
10+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
11+
<title>Contact Confirmation</title>
12+
</head>
13+
<body>
14+
<main style="width: 100%; min-height: 100vh; padding: 1rem; background-color: rgb(255 255 80 / 47%); position: relative;">
15+
<div style="margin: auto; width:90%; background-color: white; max-width: 800px; padding: 1.2rem; border-radius: 0.6rem; box-shadow: 0 1px 5px rgb(0,0,0); position: relative; justify-content: center; align-items: center;">
16+
<h1 style="margin-top: 2rem; font-family: monospace;">Thank You for Contacting Us!</h1>
17+
<p style="margin-top: 2rem; font-family: sans-serif; font-size: 1rem;">
18+
<span style="font-weight: 700;">Your Message:</span> ${message}<br><br>
19+
Thank you for reaching out to us. Your message is very important to our team, and we appreciate your interest in CodeHarborHub.
20+
<br><br>
21+
At CodeHarborHub, we are dedicated to providing you with the resources and tools to enhance your learning journey. Whether you are interested in learning new programming languages, exploring various technologies, or tackling challenging coding problems, we have something for everyone.
22+
<br><br>
23+
Here’s what you can explore at CodeHarborHub:
24+
<ul>
25+
<li><b>Courses:</b> Our comprehensive courses cover a wide range of programming languages and technologies, designed to help you build a solid foundation and advance your skills.</li><br>
26+
<li><b>Practice Challenges:</b> Put your knowledge to the test with our challenging coding problems. These exercises are crafted to sharpen your problem-solving abilities and prepare you for real-world scenarios.</li><br>
27+
<li><b>Community Support:</b> Join our vibrant community of learners and experts. Share your progress, ask questions, and collaborate with others to achieve your learning goals.</li><br>
28+
</ul>
29+
We are inspired by your enthusiasm and commitment to learning. Thank you for visiting us, and we look forward to supporting you on your educational journey.
30+
<br><br>
31+
<span style="font-family: monospace;"><b>Best regards,</b><br>
32+
The CodeHarborHub Team</span>
33+
</p>
34+
<br>
35+
<p style="font-family: monospace; font-weight: 700;">
36+
Read our Course Documentation <a href="https://codeharborhub.github.io/docs/">https://codeharborhub.github.io/docs</a>...🚀<br><br>
37+
Join Our Community <a href="https://codeharborhub.github.io/community">https://codeharborhub.github.io/community</a>..🌐<br><br>
38+
Visit our Blogs <a href="https://codeharborhub.github.io/blog">https://codeharborhub.github.io/blog</a>..🛑
39+
</p>
40+
<br><br>
41+
<p style="font-family: monospace; text-align: center;">Join Today :)</p>
42+
</div>
43+
</main>
44+
</body>
45+
</html>`;
46+
47+
const transporter = nodeMailer.createTransport({
48+
service: process.env.SERVICE,
49+
host: process.env.HOST,
50+
port: process.env.MAIL_PORT,
51+
auth: {
52+
user: process.env.USER_MAIL_ADDRESS,
53+
pass: process.env.PASS
54+
},
55+
});
56+
57+
const mailOptions = {
58+
from: process.env.USER_MAIL_ADDRESS,
59+
to: userMail,
60+
subject: `Thank you for Contacting ${name}`,
61+
text: 'Contact Us',
62+
html: HTML,
63+
};
64+
65+
try {
66+
await transporter.sendMail(mailOptions);
67+
return true;
68+
} catch (error) {
69+
console.error("Error sending email:", error);
70+
return false;
71+
}
72+
};
73+
74+
module.exports = mailing;

0 commit comments

Comments
 (0)