-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
78 lines (59 loc) · 1.55 KB
/
app.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
const express = require("express");
const routes = require("./routes");
const mongoose = require("mongoose");
const connectDB = require("./config/db");
const bodyParser = require("body-parser");
const cors = require("cors");
const passport = require("passport");
const WebSocket = require('ws');
const {
createServer
} = require("http");
require("dotenv").config();
const app = express();
connectDB();
//for meta helmet
app.use(require('prerender-node').set('prerenderToken', '4f4YkHFvjA6Ef2FQCYPd'));
app.use(express.json({
limit: "50mb"
}));
app.use(express.urlencoded({
limit: "50mb",
extended: true
}));
app.use(bodyParser.json());
app.use(
cors({
credentials: true,
origin: '*', //https://igts-web.netlify.app
})
);
console.log(process.env.FRONT_END_URL)
// Pass the global passport object into the configuration function
require("./config/passport")(passport);
// This will initialize the passport object on every request
app.use(passport.initialize());
// Routes
app.use((req, res, next) => {
req.app.set("wss", wss); // Attach the wss to req.app
next();
});
app.use(routes);
const port = process.env.PORT || 5005;
const server = createServer(app);
const wss = new WebSocket.Server({
server,
});
// WebSocket connection handler
wss.on('connection', (ws) => {
console.log('WebSocket connection established.');
ws.on('close', () => {
console.log('WebSocket connection closed.');
});
});
server.on('listening', () => {
console.log('WebSocket server started');
});
server.listen(port, () => {
console.log('Listenning');
})