-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathserver.js
33 lines (28 loc) · 938 Bytes
/
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
// server.js
const fs = require("fs");
const https = require("https");
const app = require("./app");
require("dotenv").config();
const { io, notifyUser, notifyAllUsers } = require("./routes/websocketNotification");
const PORT = process.env.PORT || 5001;
console.log(process.env.NODE_ENV);
if (process.env.NODE_ENV === "production") {
https
.createServer(
{
key: fs.readFileSync("/etc/letsencrypt/live/lfix.us/privkey.pem"),
cert: fs.readFileSync("/etc/letsencrypt/live/lfix.us/fullchain.pem")
},
app
)
.listen(PORT, () => {
console.log(`Server is running on production port ${PORT}`);
});
} else {
const server = app.listen(PORT, () => {
console.log(`Server is running in development on port ${PORT}`);
});
// Attach Socket.io to the server
io.attach(server);
}
module.exports = { notifyUser, notifyAllUsers }; // Export the notifyUser function for use elsewhere