-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
39 lines (38 loc) · 1.17 KB
/
Copy pathserver.js
File metadata and controls
39 lines (38 loc) · 1.17 KB
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
const express=require('express')
const randomString=require('randomized-string')
const app=express()
const bodyParser=require('body-parser')
const cors=require('cors')
const path=require('path')
const compression=require('compression')
const {port}=require('./config/config')
const route=require('./route')
const socketIo = require("socket.io");
const { decrptObject } = require('./auth/encrypt')
const { disconnect } = require('process')
const { webSocket } = require('./socket')
app.use('/static',express.static(path.join(__dirname,'public')));
// compress all response
app.use(compression())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended : true}));
app.use(cors())
/** routes */
app.use(route)
app.use(express.static(path.join(__dirname,'build')));
app.get('*',(req,res)=>{
res.sendFile(path.join(__dirname,'build','index.html'))
})
/**--socket connection---- */
const server = require('http').createServer(app);
const io = socketIo(server, {
cors: {
origin: "http://localhost:3000",
methods: ["GET", "POST" , "PUT"],
}
});
webSocket(io)
server.listen(port,err=>{
if (err) console.log(err)
console.log('Server up and running on localhost:'+port)
})