New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fastify-websocket

Package Overview
Dependencies
Maintainers
8
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-websocket - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0

4

index.js

@@ -49,4 +49,4 @@ 'use strict'

router.on('GET', routeOptions.path, (req, _) => {
const result = wsHandler(req[kWs], req)
router.on('GET', routeOptions.path, (req, _, params) => {
const result = wsHandler(req[kWs], req, params)

@@ -53,0 +53,0 @@ if (result && typeof result.catch === 'function') {

{
"name": "fastify-websocket",
"version": "0.5.0",
"version": "0.6.0",
"description": "basic websocket support for fastify",

@@ -27,3 +27,3 @@ "main": "index.js",

"snazzy": "^8.0.0",
"standard": "^12.0.1",
"standard": "^13.0.1",
"tap": "^12.7.0"

@@ -30,0 +30,0 @@ },

@@ -81,2 +81,10 @@ # fastify-websocket

The route handler receives route params as a third argument:
```js
fastify.get('/ws/:id', { websocket: true }, (connection, req, params) => {
connection.write(`hi on stream ${params.id}`)
})
```
However you can still pass a default global handler, that will be used as default handler.

@@ -83,0 +91,0 @@

@@ -289,1 +289,46 @@ 'use strict'

})
test('Should pass route params to handlers', t => {
const fastify = Fastify()
t.tearDown(() => fastify.close())
fastify.register(fastifyWebsocket)
fastify.get('/ws', { websocket: true }, (conn, req, params) => {
t.equal(Object.keys(params).length, 0, 'params are empty')
conn.write('empty')
conn.end()
})
fastify.get('/ws/:id', { websocket: true }, (conn, req, params) => {
t.equal(params.id, 'foo', 'params are correct')
conn.write(params.id)
conn.end()
})
fastify.listen(0, err => {
let pending = 2
t.error(err)
const client = websocket(
'ws://localhost:' + (fastify.server.address()).port + '/ws/foo'
)
const client2 = websocket(
'ws://localhost:' + (fastify.server.address()).port + '/ws'
)
t.tearDown(client.destroy.bind(client))
t.tearDown(client2.destroy.bind(client))
client.setEncoding('utf8')
client2.setEncoding('utf8')
client.once('data', chunk => {
t.equal(chunk, 'foo')
client.end()
if (--pending === 0) t.end()
})
client2.once('data', chunk => {
t.equal(chunk, 'empty')
client2.end()
if (--pending === 0) t.end()
})
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc