Skip to content

Commit

Permalink
Merge pull request #5 from Sebring/patch-1
Browse files Browse the repository at this point in the history
docs: move io event handler to app.ready
  • Loading branch information
alemagio committed Jan 11, 2021
2 parents 56b7a33 + e68876a commit 5acba86
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions examples/basic/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ const app = fastify({ logger: true })
app.register(socketio)

app.get('/', async (req, reply) => {
app.io.on('connect', () => console.info('Socket connected!'))

const data = await readFile(join(__dirname, '..', 'index.html'))
reply.header('content-type', 'text/html; charset=utf-8')
reply.send(data)
})

app.ready(err => {
if (err) throw err

app.io.on('connect', (socket) => console.info('Socket connected!', socket.id))
})

app.listen(3000)
8 changes: 6 additions & 2 deletions examples/typescript/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ const app = fastify({ logger: true })
app.register(socketioServer)

app.get('/', async (req, reply) => {
app.io.on('connect', () => console.info('Socket connected!'))

const data = await readFile(join(__dirname, '..', 'index.html'))
reply.header('content-type', 'text/html; charset=utf-8')
reply.send(data)
})

app.ready(err => {
if (err) throw err

app.io.on('connect', (socket) => console.info('Socket connected!', socket.id))
})

app.listen(3000)

0 comments on commit 5acba86

Please sign in to comment.