-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
36 lines (29 loc) · 848 Bytes
/
server.ts
File metadata and controls
36 lines (29 loc) · 848 Bytes
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
// server.ts
import { createServer } from 'http'
import { parse } from 'url'
import next from 'next'
import { Server } from 'socket.io'
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
app.prepare().then(() => {
const server = createServer((req, res) => {
const parsedUrl = parse(req.url!, true)
handle(req, res, parsedUrl)
}).listen(3000, () => {
console.log('> Ready on http://localhost:3000')
})
const io = new Server(server)
io.on('connection', (socket) => {
console.log('a user connected')
socket.on('agent-status', (msg) => {
io.emit('agent-status', msg)
})
socket.on('task-update', (msg) => {
io.emit('task-update', msg)
})
socket.on('disconnect', () => {
console.log('user disconnected')
})
})
})