Skip to content

Commit

Permalink
fix(socketio): Reinitialize hooks on overriden setup method (#2722)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Aug 17, 2022
1 parent 32df759 commit 5e8e7c4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/socketio/package.json
Expand Up @@ -55,6 +55,7 @@
"dependencies": {
"@feathersjs/commons": "^5.0.0-pre.28",
"@feathersjs/feathers": "^5.0.0-pre.28",
"@feathersjs/hooks": "^0.7.5",
"@feathersjs/transport-commons": "^5.0.0-pre.28",
"socket.io": "^4.5.1"
},
Expand Down
5 changes: 5 additions & 0 deletions packages/socketio/src/index.ts
Expand Up @@ -3,6 +3,7 @@ import { Server, ServerOptions } from 'socket.io'
import { createDebug } from '@feathersjs/commons'
import { Application } from '@feathersjs/feathers'
import { socket } from '@feathersjs/transport-commons'
import { hooks, middleware } from '@feathersjs/hooks'

import { disconnect, params, authentication, FeathersSocket } from './middleware'

Expand Down Expand Up @@ -87,6 +88,10 @@ function configureSocketio(port?: any, options?: any, config?: any) {
return setup.call(this, server, ...rest)
}
})

hooks(app, {
setup: middleware().params('server').props({ app })
})
})

app.configure(
Expand Down
13 changes: 11 additions & 2 deletions packages/socketio/test/index.test.ts
@@ -1,5 +1,5 @@
import { strict as assert } from 'assert'
import { feathers, Application, HookContext, NullableId, Params } from '@feathersjs/feathers'
import { feathers, Application, HookContext, NullableId, Params, ApplicationHookContext } from '@feathersjs/feathers'
import express from '@feathersjs/express'
import { Request, Response } from 'express'
import { omit, extend } from 'lodash'
Expand Down Expand Up @@ -80,6 +80,15 @@ describe('@feathersjs/socketio', () => {
}
})

app.hooks({
setup: [
async (context: ApplicationHookContext, next: NextFunction) => {
assert.notStrictEqual(context.app, undefined)
await next()
}
]
})

app.listen(7886).then((srv) => {
server = srv
server.once('listening', () => {
Expand All @@ -90,7 +99,7 @@ describe('@feathersjs/socketio', () => {
}
})
})
})
}).catch(done)

socket = io('http://localhost:7886')
socket.on('connect', () => done())
Expand Down

0 comments on commit 5e8e7c4

Please sign in to comment.