-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
68 lines (58 loc) · 1.88 KB
/
server.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
61
62
63
64
65
66
67
68
const express = require("express");
const cors = require("cors");
const path = require("path");
const sgMail = require("@sendgrid/mail");
require("dotenv").config();
const app = express();
const port = process.env.PORT || 4000;
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
sgMail.setApiKey(process.env.API_KEY);
app.use(cors());
//email page
app.post("/phoneRepair/address", (req, res) => {
const { Reference, Email, FirstName, LastName, Address, permit, company, color, model, issues, cost, date, time } = req.body.data;
//sendgrid reqs
const msg = {
to: Email,
cc: "[email protected]",
from: "[email protected]",
templateId: "d-724a46bd9d8e4b2ea388b56706d4f7a7",
dynamic_template_data: {
FirstName: FirstName,
Email: Email,
company: company,
model: model,
color: color,
issues: issues,
Address: Address,
permit: permit,
city: "Edmonton",
cost: cost,
date: date,
time: time,
Reference: Reference
}
};
sgMail.send(msg);
res.send("Data received");
});
if (process.env.NODE_ENV === "production") {
// Serve any static files
// app.use(express.static(path.join(__dirname, "client/build")));
app.use(express.static("client/build"));
// Handle React routing, return all requests to React app
app.get("*", function(req, res) {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
}
//welcome page
// app.get("/", (req, res) => {
// res.send("welcome to the sendgrid mail - test");
// });
app.listen(port, () => console.log(`Listening on port ${port}`));
// // "dev": "run-p dev:**",
// "dev:server": "nodemon server.js",
// "dev:app": "cd client && npm run start",
// "build:app": "cd client && npm run build",
// "heroku-postbuild": "cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build"