File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 1
1
{
2
- "name" : " socket.io-react " ,
2
+ "name" : " socket.io-complex " ,
3
3
"scripts" : {
4
4
"start" : " esno watch src/server.ts & vite"
5
5
},
Original file line number Diff line number Diff line change 1
1
import http from 'http'
2
- import axios from 'axios'
3
2
import cors from 'cors'
4
3
import express from 'express'
5
4
import { Server } from 'socket.io'
@@ -37,12 +36,23 @@ io.on('connection', (socket) => {
37
36
)
38
37
39
38
socket . on ( 'namespace.get-posts' , async ( ) => {
40
- const posts = await axios . get < Post [ ] > (
41
- 'https://jsonplaceholder.typicode.com/posts'
42
- )
39
+ const posts = [
40
+ {
41
+ userId : 1 ,
42
+ id : 2 ,
43
+ body : 'Post body' ,
44
+ title : 'Post'
45
+ } ,
46
+ {
47
+ userId : 2 ,
48
+ id : 2 ,
49
+ body : 'Post body' ,
50
+ title : 'Post 2'
51
+ }
52
+ ] satisfies Post [ ]
43
53
44
54
socket . emit ( 'namespace.posts-received' , {
45
- payload : posts . data . slice ( 0 , 10 ) ,
55
+ payload : posts . slice ( 0 , 10 ) ,
46
56
timestamp : new Date ( ) . getTime ( )
47
57
} )
48
58
} )
You can’t perform that action at this time.
0 commit comments