-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
93 lines (75 loc) · 2.28 KB
/
index.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const express = require("express");
const path = require('path');
const dotenv = require('dotenv');
const { Server } = require("socket.io");
const nodemailer = require('nodemailer');
var http = require('http');
const cors = require("cors");
dotenv.config({ path: './config/config.env' });
const app = express();
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
var server = http.createServer(app);
const io = new Server(server, {
cors: {
origin: "http://localhost:3000",
methods: ["GET", "POST"]
}
});
// app.get("/", (req, res) => {res.send("Mutables chat system backend."); res.end()});
var transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: "[email protected]",
pass: "CS554Project",
},
});
app.post("/email", (req, res) => {
const email = req.body.email;
var mailOptions = {
from: "[email protected]",
to: email,
subject: "New Account",
text: "Your Account created successfully!!",
};
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error);
} else {
console.log("Email sent: " + info.response);
}
});
res.status(200).json({success: "Message Send successfully.."});
});
app.post("/social", (req, res) => {
const email = req.body.email;
var mailOptions = {
from: "[email protected]",
to: email,
subject: "New log in",
text: "Your Account was signed in to The Mutables Ticket Website!!",
};
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error);
} else {
console.log("Email sent: " + info.response);
}
});
res.status(200).json({success: "Message Send successfully.."});
})
io.on("connection", (socket) => {
socket.on("joinRoom", room => {
socket.join(room)
})
socket.on("newMessage", ({newMessage, room}) => {
io.in(room).emit("getLatestMessage", newMessage)
})
});
if(process.env.NODE_ENV === 'production') {
app.use(express.static('ticket_frontend/build'));
app.get('*', (req, res) => res.sendFile(path.resolve(__dirname, 'ticket_frontend', 'build', 'index.html')));
}
const port = process.env.PORT || 9000
server.listen(port, console.log(`Server Created on port ${port}`))