-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (30 loc) · 827 Bytes
/
index.js
File metadata and controls
36 lines (30 loc) · 827 Bytes
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
const express = require("express");
const { json } = require("body-parser");
const cors = require("cors");
const { mail } = require("./sendMail");
require("dotenv").config();
const app = express();
const PORT = process.env.PORT || 3046;
// Middleware
app.use(json());
app.use(cors());
// Routes
app.get("/", (req, res) => {
res.send("Working");
});
app.post("/send/message", (req, res) => {
const messageData = req.body;
if (!messageData) {
return res.status(400).send("No message data provided");
}
mail(messageData)
.then(() => res.status(200).send("Message Sent"))
.catch((error) => {
console.error("Error sending message:", error);
res.status(500).send("Internal Server Error");
});
});
// Start server
app.listen(PORT, () => {
console.log(`Server is running on ${PORT}`);
});