2020-01-21 19:19:18 +00:00
|
|
|
// Copyright IBM Corp. 2014,2019. All Rights Reserved.
|
2016-05-03 22:50:21 +00:00
|
|
|
// Node module: loopback
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
2014-06-05 00:42:18 +00:00
|
|
|
/*!
|
2013-11-19 20:35:29 +00:00
|
|
|
* Export the middleware.
|
|
|
|
*/
|
|
|
|
|
2016-11-15 21:46:23 +00:00
|
|
|
'use strict';
|
2013-11-19 20:35:29 +00:00
|
|
|
module.exports = status;
|
|
|
|
|
2014-06-05 00:42:18 +00:00
|
|
|
/**
|
|
|
|
* Return [HTTP response](http://expressjs.com/4x/api.html#res.send) with basic application status information:
|
|
|
|
* date the application was started and uptime, in JSON format.
|
|
|
|
* For example:
|
|
|
|
* ```js
|
|
|
|
* {
|
|
|
|
* "started": "2014-06-05T00:26:49.750Z",
|
|
|
|
* "uptime": 9.394
|
|
|
|
* }
|
|
|
|
* ```
|
2014-10-16 22:54:40 +00:00
|
|
|
*
|
2014-06-05 00:42:18 +00:00
|
|
|
* @header loopback.status()
|
|
|
|
*/
|
2013-11-19 20:35:29 +00:00
|
|
|
function status() {
|
2019-10-07 09:45:34 +00:00
|
|
|
const started = new Date();
|
2013-11-19 20:35:29 +00:00
|
|
|
|
|
|
|
return function(req, res) {
|
|
|
|
res.send({
|
|
|
|
started: started,
|
2016-04-01 09:14:26 +00:00
|
|
|
uptime: (Date.now() - Number(started)) / 1000,
|
2013-11-19 20:35:29 +00:00
|
|
|
});
|
2014-10-16 22:54:40 +00:00
|
|
|
};
|
2013-11-19 20:35:29 +00:00
|
|
|
}
|