Skip to content

Commit

Permalink
Restore fastify v3 compat (#556)
Browse files Browse the repository at this point in the history
* Revert "fix: update under-pressure -> @fastify/under-pressure (#550)"

This reverts commit 105ef17.

* v8.0.0 is [email protected] only

Signed-off-by: Matteo Collina <[email protected]>
  • Loading branch information
mcollina authored Jun 14, 2022
1 parent a83feb7 commit 678c35b
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 570 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ fastify
})
```

### @fastify/under-pressure
### under-pressure

The plugin includes [@fastify/under-pressure](https://github.com/fastify/under-pressure), which can be configured by providing an `underPressure` property to the plugin options.
The plugin includes [under-pressure](https://github.com/fastify/under-pressure), which can be configured by providing an `underPressure` property to the plugin options.

Using `@fastify/under-pressure` allows implementing a circuit breaker that returns an error when the health metrics are not respected.
Using `under-pressure` allows implementing a circuit breaker that returns an error when the health metrics are not respected.
Because React server side rendering is a blocking operation for the Node.js server, returning an error to the client allows signalling that the server is under too much load.

The available options are the same as those accepted by `@fastify/under-pressure`.
The available options are the same as those accepted by `under-pressure`.

For example:

Expand All @@ -112,9 +112,9 @@ fastify.register(require('@fastify/nextjs'), {

- `underPressure` - `bool|object`

- (default) when false, `@fastify/under-pressure` is not registered
- when true, `@fastify/under-pressure` is registered with default options
- when it is an object, `@fastify/under-pressure` is registered with the provided options
- (default) when false, `under-pressure` is not registered
- when true, `under-pressure` is registered with default options
- when it is an object, `under-pressure` is registered with the provided options

## Custom properties on the request object
If you want to share custom objects (for example other fastify plugin instances - e.g. @fastify/redis) across the server/client with each page request, you can use the `onRequest` hook to add it to the request object.
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
} from 'fastify';
import type { RouteGenericInterface, RouteShorthandOptions } from 'fastify/types/route';
import { NextServer } from 'next/dist/server/next';
import underPressure from '@fastify/under-pressure';
import underPressure from 'under-pressure';

declare module 'fastify' {
type FastifyNextCallback = (
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function fastifyNext (fastify, options, next) {
if (underPressure) {
const opts = typeof underPressure === 'object' ? underPressure : Object.create(null)

fastify.register(require('@fastify/under-pressure'), opts)
fastify.register(require('under-pressure'), opts)
}

const app = Next(Object.assign({}, { dev: process.env.NODE_ENV !== 'production' }, nextOptions))
Expand Down Expand Up @@ -107,6 +107,6 @@ function fastifyNext (fastify, options, next) {
}

module.exports = fp(fastifyNext, {
fastify: '>=3.22.1',
fastify: '3.x',
name: '@fastify/nextjs'
})
Loading

0 comments on commit 678c35b

Please sign in to comment.