From 58fb3277b61f525726c4e1a0769fe13c5fa3971a Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Tue, 6 Apr 2021 08:02:01 +0100 Subject: [PATCH 1/6] docs(readme): add badges --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6c47cf5..0b0b830 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # fastify-websocket -[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) -![CI -workflow](https://github.com/fastify/fastify-websocket/workflows/CI%20workflow/badge.svg) +![CI](https://github.com/fastify/fastify-websocket/workflows/CI/badge.svg) +[![NPM version](https://img.shields.io/npm/v/fastify-websocket.svg?style=flat)](https://www.npmjs.com/package/fastify-websocket) +[![Known Vulnerabilities](https://snyk.io/test/github/fastify/fastify-websocket/badge.svg)](https://snyk.io/test/github/fastify/fastify-websocket) +[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/) WebSocket support for [Fastify](https://github.com/fastify/fastify). Built upon [ws](https://www.npmjs.com/package/ws). From 85e2ca1ac80eb53ccd0828d992e32c569bb0744d Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Tue, 6 Apr 2021 08:55:03 +0100 Subject: [PATCH 2/6] ci: ignore documentation updates --- .github/workflows/ci.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9e6ab0..07dcfac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,14 @@ name: CI workflow -on: [push, pull_request] + +on: + push: + paths-ignore: + - 'docs/**' + - '*.md' + pull_request: + paths-ignore: + - 'docs/**' + - '*.md' jobs: test: runs-on: ubuntu-latest From c324da0e5960840e360955911f160de1c328ab6d Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Tue, 6 Apr 2021 08:55:40 +0100 Subject: [PATCH 3/6] ci: test on multiple os --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07dcfac..c38fc53 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,10 +11,11 @@ on: - '*.md' jobs: test: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} strategy: matrix: node-version: [10.x, 12.x, 14.x] + os: [macos-latest, ubuntu-latest, windows-latest] steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} From ed15f7b52294c825d49c5136ab7a482bf7b88dc5 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Tue, 6 Apr 2021 08:56:05 +0100 Subject: [PATCH 4/6] style(ci): use standardized template --- .github/workflows/ci.yml | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c38fc53..539b3f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: CI workflow +name: CI on: push: @@ -9,29 +9,36 @@ on: paths-ignore: - 'docs/**' - '*.md' + jobs: test: runs-on: ${{ matrix.os }} + strategy: matrix: node-version: [10.x, 12.x, 14.x] os: [macos-latest, ubuntu-latest, windows-latest] + steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2.1.5 - with: - node-version: ${{ matrix.node-version }} - - name: Install Dependencies - run: npm install --ignore-scripts - - name: Test - run: npm test + - uses: actions/checkout@v2 + + - name: Use Node.js + uses: actions/setup-node@v2.1.5 + with: + node-version: ${{ matrix.node-version }} + + - name: Install Dependencies + run: | + npm install --ignore-scripts + + - name: Run Tests + run: | + npm run test automerge: needs: test runs-on: ubuntu-latest steps: - uses: fastify/github-action-merge-dependabot@v2.0.0 - if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' }} with: - github-token: ${{secrets.github_token}} + github-token: ${{ secrets.GITHUB_TOKEN }} From 14d3641f139d2e9252adca05f6d0072f176f452a Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Tue, 6 Apr 2021 09:02:50 +0100 Subject: [PATCH 5/6] docs(readme): minor fixes --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0b0b830..00585ff 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ fastify.listen(3000, err => { In this case, it will respond with a 404 error on every unregistered route, closing the incoming upgrade connection requests. -However you can still define a wildcard route, that will be used as default handler. +However, you can still define a wildcard route, that will be used as default handler. ```js 'use strict' @@ -77,9 +77,9 @@ fastify.listen(3000, err => { ### Attaching event handlers -It is important that websocket route handlers attach event handlers synchronously during handler execution to avoid accidentally dropping messages. If you want to do any async work in your websocket handler, say to authenticate a user or load data from a datastore, ensure you attach any `on('message')` handlers *before* you trigger this async work. Otherwise, messages might arrive while this async work is underway, and if there is no handler listening for this data, it will be silently dropped. +It is important that websocket route handlers attach event handlers synchronously during handler execution to avoid accidentally dropping messages. If you want to do any async work in your websocket handler, say to authenticate a user or load data from a datastore, ensure you attach any `on('message')` handlers *before* you trigger this async work. Otherwise, messages might arrive whilst this async work is underway, and if there is no handler listening for this data it will be silently dropped. -Here's an example of how to attach message handlers synchronously while still accessing asynchronous resources. We store a promise for the async thing in a local variable, and then attach the message handler synchronously, and then make the message handler itself asynchronous to grab the async data and do some processing. +Here is an example of how to attach message handlers synchronously while still accessing asynchronous resources. We store a promise for the async thing in a local variable, attach the message handler synchronously, and then make the message handler itself asynchronous to grab the async data and do some processing. ```javascript fastify.get('/*', { websocket: true }, (connection, request) => { @@ -223,13 +223,13 @@ fastify.listen(3000, err => { - `perMessageDeflate` - Enable/disable permessage-deflate. - `maxPayload` - The maximum allowed message size in bytes. -For more informations you can check [`ws` options documentation](https://github.com/websockets/ws/blob/master/doc/ws.md#new-websocketserveroptions-callback). +For more information, you can check [`ws` options documentation](https://github.com/websockets/ws/blob/master/doc/ws.md#new-websocketserveroptions-callback). _**NB:** By default if you do not provide a `server` option `fastify-websocket` will bind your websocket server instance to the scoped `fastify` instance._ -_**NB:** the `path` option from `ws` shouldn't be provided since the routing is handled by fastify itself_ +_**NB:** the `path` option from `ws` should not be provided since the routing is handled by fastify itself_ -_**NB:** the `noServer` option from `ws` shouldn't be provided since the point of fastify-websocket is to listen on the fastify server. If you want a custom server, you can use the `server` option, and if you want more control, you can use the `ws` library directly_ +_**NB:** the `noServer` option from `ws` should not be provided since the point of fastify-websocket is to listen on the fastify server. If you want a custom server, you can use the `server` option, and if you want more control, you can use the `ws` library directly_ ## Acknowledgements From ed7fb17aae7aa6a62a0bf42654a764e3710b056f Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Tue, 6 Apr 2021 09:03:07 +0100 Subject: [PATCH 6/6] docs(readme): update http link to https --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 00585ff..3119113 100644 --- a/README.md +++ b/README.md @@ -233,7 +233,7 @@ _**NB:** the `noServer` option from `ws` should not be provided since the point ## Acknowledgements -This project is kindly sponsored by [nearForm](http://nearform.com). +This project is kindly sponsored by [nearForm](https://nearform.com). ## License