Skip to content

Commit

Permalink
Merge pull request #23 from fastify/prep-next
Browse files Browse the repository at this point in the history
Fixes for Fastify 2.x
  • Loading branch information
cemremengu authored Jan 8, 2019
2 parents 9ceb241 + cc4e2fa commit da6be39
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ It can check `maxEventLoopDelay`, `maxHeapUsedBytes` and `maxRssBytes` values.
<a name="requirements"></a>
## Requirements

Fastify ^1.1.0 .
Fastify ^2.0.0. Please refer to [this branch](https://github.com/fastify/under-pressure/tree/1.x) and related versions for Fastify ^1.1.0 compatibility.

<a name="install"></a>
## Install
Expand Down
15 changes: 7 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,27 @@ function underPressure (fastify, opts, next) {
lastCheck = toCheck
}

function onRequest (req, res, next) {
function onRequest (req, reply, next) {
if (checkMaxEventLoopDelay && eventLoopDelay > maxEventLoopDelay) {
sendError(res, next)
sendError(reply, next)
return
}

if (checkMaxHeapUsedBytes && heapUsed > maxHeapUsedBytes) {
sendError(res, next)
sendError(reply, next)
return
}

if (checkMaxRssBytes && rssBytes > maxRssBytes) {
sendError(res, next)
sendError(reply, next)
return
}

next()
}

function sendError (res, next) {
res.statusCode = 503
res.setHeader('Retry-After', retryAfter)
function sendError (reply, next) {
reply.status(503).header('Retry-After', retryAfter)
next(serviceUnavailableError)
}

Expand Down Expand Up @@ -110,6 +109,6 @@ function now () {
}

module.exports = fp(underPressure, {
fastify: '^1.1.0',
fastify: '>=2.0.0',
name: 'under-pressure'
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"fastify-plugin": "^1.4.0"
},
"devDependencies": {
"fastify": "^1.13.3",
"fastify": "2.0.0-rc.3",
"pre-commit": "^1.2.2",
"simple-get": "^3.0.3",
"snazzy": "^8.0.0",
Expand Down

0 comments on commit da6be39

Please sign in to comment.