Skip to content

Commit

Permalink
chore: doc and ci updates (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs authored Apr 13, 2021
1 parent 59c640c commit 901bdc5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
30 changes: 18 additions & 12 deletions .github/workflows/nodejs.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
name: Node CI

on: [push, pull_request]
name: CI

on:
push:
paths-ignore:
- 'docs/**'
- '*.md'
pull_request:
paths-ignore:
- 'docs/**'
- '*.md'

jobs:
test:
name: Test
runs-on: ${{ matrix.os }}

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
os: [ubuntu-latest, macOS-latest, windows-latest]
os: [macos-latest, ubuntu-latest, windows-latest]

steps:
- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
- name: Use Node.js
uses: actions/setup-node@v2.1.5
with:
node-version: ${{ matrix.node-version }}

- name: Install
- name: Install Dependencies
run: |
npm install
npm install --ignore-scripts
- name: Test
- name: Run Tests
run: |
npm test
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 }}
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# fastify-sensible

[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) ![Node CI](https://github.com/fastify/fastify-sensible/workflows/Node%20CI/badge.svg)
![CI](https://github.com/fastify/fastify-sensible/workflows/CI/badge.svg)
[![NPM version](https://img.shields.io/npm/v/fastify-sensible.svg?style=flat)](https://www.npmjs.com/package/fastify-sensible)
[![Known Vulnerabilities](https://snyk.io/test/github/fastify/fastify-sensible/badge.svg)](https://snyk.io/test/github/fastify/fastify-sensible)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)

Defaults for Fastify that everyone can agree on™.<br>
This plugin adds some useful utilities to your Fastify instance, see the API section to learn more.
Expand All @@ -9,7 +12,7 @@ Supports Fastify versions `3.x`.
Please refer to [this branch](https://github.com/fastify/fastify-sensible/tree/2.x) and related versions for Fastify `2.x` compatibility.
Please refer to [this branch](https://github.com/fastify/fastify-sensible/tree/1.x) and related versions for Fastify `1.x` compatibility.

*Why these APIs are here and not directly into core?<br>
*Why are these APIs here and not included with Fastify?<br>
Because Fastify aims to be as small and focused as possible, every utility that is not essential should be shipped as standalone plugin.*

## Install
Expand Down Expand Up @@ -97,15 +100,15 @@ var err = fastify.httpErrors.createError(404, 'This video does not exist!')
```

#### `reply.[httpError]`
The `reply` interface is decorated with all the functions declared above, use it is very easy:
The `reply` interface is decorated with all the functions declared above, using it is very easy:
```js
fastify.get('/', (req, reply) => {
reply.notFound()
})
```

#### `reply.vary`
The `reply` interface is decorated with [`jshttp/vary`](https://github.com/jshttp/vary), the API is the same, but you don't need to pass the res object.
The `reply` interface is decorated with [`jshttp/vary`](https://github.com/jshttp/vary), the API is the same, but you do not need to pass the res object.
```js
fastify.get('/', (req, reply) => {
reply.vary('Accept')
Expand All @@ -114,23 +117,23 @@ fastify.get('/', (req, reply) => {
```

#### `request.forwarded`
The `request` interface is decorated with [`jshttp/forwarded`](https://github.com/jshttp/forwarded), the API is the same, but you don't need to pass the request object.
The `request` interface is decorated with [`jshttp/forwarded`](https://github.com/jshttp/forwarded), the API is the same, but you do not need to pass the request object:
```js
fastify.get('/', (req, reply) => {
reply.send(req.forwarded())
})
```

#### `request.is`
The `request` interface is decorated with [`jshttp/type-is`](https://github.com/jshttp/type-is), the API is the same, but you don't need to pass the request object.
The `request` interface is decorated with [`jshttp/type-is`](https://github.com/jshttp/type-is), the API is the same, but you do not need to pass the request object:
```js
fastify.get('/', (req, reply) => {
reply.send(req.is(['html', 'json']))
})
```

#### `assert`
Verify if a given condition is true, if not it throws the specified http error.<br> Very useful if you work with *async* routes.
Verify if a given condition is true, if not it throws the specified http error.<br> Very useful if you work with *async* routes:
```js
// the custom message is optional
fastify.assert(
Expand All @@ -147,7 +150,7 @@ The `assert` API exposes also the following methods:
- <code>fastify.assert.<b>notDeepEqual()</b></code>

#### `to`
Async await wrapper for easy error handling without try-catch, inspired by [`await-to-js`](https://github.com/scopsy/await-to-js)
Async await wrapper for easy error handling without try-catch, inspired by [`await-to-js`](https://github.com/scopsy/await-to-js):

```js
const [err, user] = await fastify.to(
Expand All @@ -156,7 +159,7 @@ const [err, user] = await fastify.to(
```

#### Custom error handler
This plugins also adds a custom error handler which hides the error message in case of `500` errors that are being generated by throwed errors, instead it returns `Something went wrong`.<br>
This plugins also adds a custom error handler, which hides the error message in case of `500` errors that are being generated by throwed errors, instead it returns `Something went wrong`.<br>
This is especially useful if you are using *async* routes, where every uncaught error will be sent back to the user *(but do not worry, the original error message is logged as error in any case)*.
If needed, it can be disabled by setting the option `errorHandler` to `false`.

Expand Down

0 comments on commit 901bdc5

Please sign in to comment.