Skip to content

Commit

Permalink
fix: socket.io-complex example
Browse files Browse the repository at this point in the history
  • Loading branch information
gearonix committed Mar 3, 2024
1 parent 93f53cb commit b415436
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sample/socket.io-complex/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "socket.io-react",
"name": "socket.io-complex",
"scripts": {
"start": "esno watch src/server.ts & vite"
},
Expand Down
20 changes: 15 additions & 5 deletions sample/socket.io-complex/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import http from 'http'
import axios from 'axios'
import cors from 'cors'
import express from 'express'
import { Server } from 'socket.io'
Expand Down Expand Up @@ -37,12 +36,23 @@ io.on('connection', (socket) => {
)

socket.on('namespace.get-posts', async () => {
const posts = await axios.get<Post[]>(
'https://jsonplaceholder.typicode.com/posts'
)
const posts = [
{
userId: 1,
id: 2,
body: 'Post body',
title: 'Post'
},
{
userId: 2,
id: 2,
body: 'Post body',
title: 'Post 2'
}
] satisfies Post[]

socket.emit('namespace.posts-received', {
payload: posts.data.slice(0, 10),
payload: posts.slice(0, 10),
timestamp: new Date().getTime()
})
})
Expand Down

0 comments on commit b415436

Please sign in to comment.