-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
60 lines (52 loc) · 1.29 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import express from "express";
import { config } from "dotenv";
import cors from "cors";
import { sendEmail } from "./utils/sendEmail.js";
const app = express();
const router = express.Router();
config({ path: "./config.env" });
app.use(
cors({
origin: "https://gym-backend-o4pz.onrender.com/",
methods: ["POST"],
credentials: true,
})
);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
router.get('/' , (req,res) => {
res.send('Welcome to the email sender API')
})
// API send mail
router.post("/send/mail", async (req, res, next) => {
const { name, email, message } = req.body;
if (!name || !email || !message) {
return next(
res.status(400).json({
success: false,
message: "Please provide all details",
})
);
}
try {
await sendEmail({
email: "vanshitthummar11@gmail.com",
subject: "GYM WEBSITE CONTACT",
message,
userEmail: email,
});
res.status(200).json({
success: true,
message: "Message Sent Successfully.",
});
} catch (error) {
res.status(500).json({
success: false,
message: " Internal Server Error",
});
}
});
app.use(router);
app.listen(process.env.PORT, () => {
console.log(`Server listening at port ${process.env.PORT}`);
});