-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Base healthcheck * Readme * Browser info * Docstring * bad browser status
- Loading branch information
1 parent
02c0fd9
commit 3999149
Showing
5 changed files
with
79 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,6 @@ router.post('/', async function (req, res, next) { | |
} catch (e) { | ||
next(e); | ||
} | ||
|
||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ router.post('/', async function (req, res, next) { | |
} catch (e) { | ||
next(e); | ||
} | ||
|
||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
|
||
/** | ||
* HealthCheck endpoint. | ||
* Sends 2xx status code if the server is up, | ||
* 5xx otherwise. | ||
* As a response returns an object: | ||
* { | ||
* timestamp: timestamp, | ||
* uptime: number, | ||
* message: string, | ||
* browser: { // browser info | ||
* connection: boolean, | ||
* version: string, | ||
* contexts: number, | ||
* pages: number, | ||
* } | ||
* } | ||
**/ | ||
router.get('/', async (req, res, next) => { | ||
const healthCheck = { | ||
timestamp: Date.now(), | ||
uptime: process.uptime(), | ||
message: "OK", | ||
}; | ||
|
||
const browser = req.app.get('browser'); | ||
if (browser) { | ||
healthCheck.browser = { | ||
connection: browser.isConnected(), | ||
version: await browser.version(), | ||
contexts: browser.browserContexts().length, | ||
pages: (await browser.pages()).length, | ||
} | ||
} else { | ||
res.status(503); // Service Unavailable | ||
healthCheck.message = "Browser is undefined"; | ||
} | ||
|
||
try { | ||
res.send(healthCheck); | ||
} catch (e) { | ||
healthCheck.message = e.toString(); | ||
res.status(503); // Service Unavailable | ||
res.send(healthCheck); | ||
} | ||
}); | ||
|
||
module.exports = router; |