-
-
Save wthrajat/51886db4949b270d5835eb52943106a0 to your computer and use it in GitHub Desktop.
Simple JS code for node healthcheck ping
This file contains hidden or 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
| async function sendHealthCheck() { | |
| const now = new Date(); | |
| const timestamp = now | |
| .toISOString() | |
| .replace(/\.\d{3}/, '') | |
| .replace('Z', '+0000'); | |
| const signature = 'your signature here'; | |
| const graphqlMutation = { | |
| query: ` | |
| mutation HealthCheck($signature: String!, $timestamp: String!) { | |
| healthCheck(signature: $signature, timestamp: $timestamp) | |
| } | |
| `, | |
| variables: { | |
| signature: signature, | |
| timestamp: timestamp, | |
| }, | |
| }; | |
| try { | |
| const response = await fetch('https://api.amboss.space/graphql', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| body: JSON.stringify(graphqlMutation), | |
| }); | |
| const result = await response.json(); | |
| if (result.errors) { | |
| console.error('GraphQL Errors:', result.errors); | |
| } else { | |
| console.log('Heartbeat sent successfully:', result.data.healthCheck); | |
| } | |
| } catch (err) { | |
| console.error('Failed to send heartbeat:', err); | |
| } | |
| } | |
| await sendHealthCheck(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment