-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
85 lines (68 loc) · 1.97 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
79
80
81
82
83
84
85
/* eslint-disable no-console */
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const cors = require("cors");
const http = require("http");
const server = http.createServer(app);
const stream = require("./socket/stream.js");
const io = require("socket.io")(server, {
cors: {
origin: "*",
methods: [ "GET", "POST" ]
}
});
require("dotenv").config();
const routes = require("./routes/routes");
// setup body parser
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cors());
// allowing cors
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
next();
});
(async () => {
try {
const options = {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true,
autoIndex: false,
};
// connect you DB here
await mongoose.connect("mongodb+srv://olashina:[email protected]/Medicx?retryWrites=true&w=majority", options);
console.log("connected to DB");
} catch (err) {
console.log(err.toString());
}
})();
app.get("/", (req, res) => {
res.status(200).send({
message: "Server Up",
});
});
// Spin up dev server
const PORT = process.env.PORT || 8080;
// io.on("connection", (socket) => {
// socket.emit("me", socket.id);
// socket.on("disconnect", () => {
// socket.broadcast.emit("callEnded");
// })
// socket.on("callUser", (data) => {
// io.to(data.userToCall).emit("callUser", { signal: data.signalData, from: data.from, name: data.name});
// })
// socket.on("answerCall", (data) => io.to(data.to).emit("callAccepted"), data.signal )
// })
io.of( '/stream' ).on( 'connection', stream );
app.use("/api", routes);
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});