-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
59 lines (49 loc) · 1.37 KB
/
server.js
File metadata and controls
59 lines (49 loc) · 1.37 KB
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
const fs = require("fs");
const cors = require("cors");
const express = require("express");
const bodyParser = require("body-parser");
var nodemailer = require("nodemailer");
var smtpTransport = require("nodemailer-smtp-transport");
const app = express();
const path = require("path");
app.use(cors());
app.use(express.json());
app.use(bodyParser.json());
const dotenv = require("dotenv");
dotenv.config();
app.use(express.static(path.join(__dirname, "/build")));
const PORT = process.env.PORT || 4200;
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "build", "index.html"));
});
let transporter = nodemailer.createTransport(
smtpTransport({
service: "gmail",
host: "smtp.gmail.com",
secure: false,
port: 25,
auth: {
user: process.env.GOOGLE_MAIL,
pass: process.env.GOOGLE_PASS,
},
tls: {
rejectUnauthorized: false,
},
})
);
app.post("/api/message/", function (req, res) {
var mailOptions = {
to: process.env.GOOGLE_MAIL,
subject: "הודעה מדף קורות חיים",
text: `הודעה: ${req.body.message} `,
};
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error);
} else {
console.log("Email sent: " + info.response);
}
});
});
app.listen(PORT, () => console.log(`Listening on port ${PORT}`));
// "proxy": "http://localhost:4200",