fastify-websocket
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -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() | ||
}) | ||
}) | ||
}) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
21272
440
190
3