-
Notifications
You must be signed in to change notification settings - Fork 0
/
healthcheck.js
62 lines (55 loc) · 1.89 KB
/
healthcheck.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* -----------------------------------------------------------------------------
* Copyright (c) 2023, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* No Patent Rights, Trademark Rights and/or other Intellectual Property
* Rights other than the rights under this license are granted.
* All other rights reserved.
*
* For any other rights, a separate agreement needs to be closed.
*
* For more information please contact:
* Fraunhofer FOKUS
* Kaiserin-Augusta-Allee 31
* 10589 Berlin, Germany
* https://www.fokus.fraunhofer.de/go/fame
* -----------------------------------------------------------------------------
*/
const http = require('http'); // Use 'https' if your API is served over HTTPS
const PORT = process.env.PORT || 3000;
const options = {
hostname: 'localhost',
port: PORT, // Use 443 if using HTTPS
path: '/health',
method: 'GET',
timeout: 5000, // 5 seconds timeout
};
const req = http.request(options, (res) => {
if (res.statusCode === 200) {
process.exit(0);
} else {
process.exit(1);
}
});
req.on('error', (error) => {
console.error(error);
process.exit(1);
});
req.on('timeout', () => {
console.error('Request timed out');
req.destroy();
process.exit(1);
});
req.end();