-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
62 lines (41 loc) · 1.34 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
const dotenv = require("dotenv").config();
const express = require("express");
const cors = require("cors");
const path = require("path");
const exp = require("constants");
const connectDB = require("./config/mongoos");
const app = express();
const PORT = process.env.PORT;
connectDB();
app.use(cors());
app.use(express.json());
dotenv;
//setting up chat socket //
const chatServer = require("http").Server(app);
const chatSocket = require("./config/chatSocket").chatSocket(chatServer);
app.use("/uploads", express.static(__dirname + "/uploads"));
chatServer.listen(4000, (err) => {
if (err) {
("error in listening chat server");
} else {
console.log("chat server is running successfully on port : 4000");
}
});
//api for authentication //
app.use("/api/auth", require("./routes/auth"));
//api for chat //
app.use("/api/chat", require("./routes/chat"));
// ------------------------Deployment---------------
const __dirname1 = path.resolve();
app.use(express.static(path.join(__dirname1,'frontend_build')))
app.get('*',(req,res)=>{
res.sendFile(path.resolve(__dirname1,"frontend_build","index.html"))
});
//------------------------Deployment-----------
app.listen(PORT, function (err) {
if (err) {
console.log("error in running server", PORT);
} else {
console.log("server is running succefully on port:", PORT);
}
});