-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
56 lines (41 loc) · 1.16 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
const dotenv = require('dotenv');
dotenv.config()
const express = require("express")
const app = express()
const cors = require("cors")
const mongoose = require("./database")
const port = process.env.PORT || 3003
const server = app.listen(port, () => {
console.log(`Server running on port ${port}`)
})
const io = require("socket.io")(server, {
pingTimeOut: 60000,
cors: {
origin: "*",
methods: ["GET", "POST", "PUT"]
},
})
app.use(cors({
origin: '*'
}))
app.options('*', cors())
app.use(express.json())
app.use(express.urlencoded({extended: true}));
// API Routes
const usersAPI = require("./routes/api/users")
const apisAPI = require("./routes/api/apis")
const tokensAPI = require("./routes/api/tokens")
app.use('/api/users', usersAPI)
app.use('/api/apis', apisAPI)
app.use('/api/tokens', tokensAPI)
app.get("/", (req, res) => {
res.status(200).send("Hello World!")
})
io.on("connection", (socket) => {
socket.on("join room", sessionId => socket.join(sessionId))
socket.on("authorized token", (data) => {
let token = data.token
let sessionId = data.sessionId
socket.in(sessionId).emit("trusted token", token)
})
})