* Checks if client IP address is allowed to make http request to * S3 server. Defines function 'healthcheckEndHandler', which is * called if IP not allowed or passed as callback. * @param {object} clientIP - IP address of client * @param {object} req - http request object * @param {object} res
(clientIP, req, res, log, statsClient, deep)
| 123 | * @return {undefined} |
| 124 | */ |
| 125 | function healthcheckHandler(clientIP, req, res, log, statsClient, deep) { |
| 126 | function healthcheckEndHandler(err, results) { |
| 127 | writeResponse(res, err, log, results, error => { |
| 128 | if (error) { |
| 129 | return log.end().warn('healthcheck error', { err: error }); |
| 130 | } |
| 131 | return log.end(); |
| 132 | }); |
| 133 | } |
| 134 | |
| 135 | // Attach the apiMethod method to the request, so it can used by monitoring in the server |
| 136 | // eslint-disable-next-line no-param-reassign |
| 137 | req.apiMethod = deep ? 'deepHealthcheck' : 'healthcheck'; |
| 138 | |
| 139 | if (!checkIP(clientIP)) { |
| 140 | return healthcheckEndHandler(errors.AccessDenied, []); |
| 141 | } |
| 142 | return routeHandler(deep, req, res, log, statsClient, |
| 143 | healthcheckEndHandler); |
| 144 | } |
| 145 | |
| 146 | module.exports = { |
| 147 | isHealthy, |
no test coverage detected