-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
41 lines (32 loc) · 1004 Bytes
/
server.js
File metadata and controls
41 lines (32 loc) · 1004 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
37
38
39
40
41
const bodyParser = require("body-parser");
let serveStatic = require("serve-static");
let history = require("connect-history-api-fallback");
let express = require("express"),
path = require("path"),
app = express(),
cors = require("cors"),
sgMail = require("@sendgrid/mail");
require("dotenv").config();
sgMail.setApiKey(process.env.SENDGRID);
app.use(history());
app.use(bodyParser());
app.use(cors());
const PORT = process.env.PORT || 3010;
app.set("port", process.env.PORT || 3010);
app.use(serveStatic(path.join(__dirname, "/dist")));
app.listen(PORT, function() {
console.log("Node.js server is running on port " + PORT);
});
app.post("/api", (req, res) => {
console.log(req.body);
const { name, email, subject, message } = req.body.messageToSend;
const msg = {
to: "martin1olasz@gmail.com",
from: email,
subject: subject,
text: name,
html: `<strong>${message}</strong><p>${name}</p>`,
};
sgMail.send(msg);
res.send("Successfully! Sent mail");
});