Skip to content

Commit b415436

Browse files
committed
fix: socket.io-complex example
1 parent 93f53cb commit b415436

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

sample/socket.io-complex/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "socket.io-react",
2+
"name": "socket.io-complex",
33
"scripts": {
44
"start": "esno watch src/server.ts & vite"
55
},

sample/socket.io-complex/src/server.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import http from 'http'
2-
import axios from 'axios'
32
import cors from 'cors'
43
import express from 'express'
54
import { Server } from 'socket.io'
@@ -37,12 +36,23 @@ io.on('connection', (socket) => {
3736
)
3837

3938
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[]
4353

4454
socket.emit('namespace.posts-received', {
45-
payload: posts.data.slice(0, 10),
55+
payload: posts.slice(0, 10),
4656
timestamp: new Date().getTime()
4757
})
4858
})

0 commit comments

Comments
 (0)