Skip to content

Instantly share code, notes, and snippets.

@typebird
Created May 19, 2020 05:49
Show Gist options
  • Save typebird/c94e0d5ddc60f3a0492b47dc7f5bec4a to your computer and use it in GitHub Desktop.
Save typebird/c94e0d5ddc60f3a0492b47dc7f5bec4a to your computer and use it in GitHub Desktop.
fastify mod
import fp from "fastify-plugin"
import SocketIOServer from "socket.io"
import type { FastifyInstance, FastifyError } from "fastify"
export default fp((
fastify: FastifyInstance,
options: any,
next: (err?: FastifyError | undefined) => void) => {
try {
const io = SocketIOServer(fastify.server, options)
fastify.decorate("io", io)
next()
} catch (error) {
next(error)
}
}, {
name: "fastify-socket.io",
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment