Skip to content

A local-first personal finance app

Add a health check script (#214)

Jed Fox5252f4507335
diff --git a/package.json b/package.json
index dfe53b226d..e596e8263e 100644
--- a/package.json
+++ b/package.json
@@ -11,7 +11,8 @@
"test": "NODE_ENV=test NODE_OPTIONS='--experimental-vm-modules --trace-warnings' jest --coverage",
"types": "tsc --noEmit --incremental",
"verify": "yarn -s lint && yarn types",
- "reset-password": "node src/scripts/reset-password.js"
+ "reset-password": "node src/scripts/reset-password.js",
+ "health-check": "node src/scripts/health-check.js"
},
"dependencies": {
"@actual-app/api": "6.1.0",
diff --git a/src/scripts/health-check.js b/src/scripts/health-check.js
new file mode 100644
index 0000000000..6cce6d1352
--- /dev/null
+++ b/src/scripts/health-check.js
@@ -0,0 +1,20 @@
+import fetch from 'node-fetch';
+import config from '../load-config.js';
+
+let protocol = config.https ? 'https' : 'http';
+let hostname = config.hostname === '::' ? 'localhost' : config.hostname;
+
+fetch(`${protocol}://${hostname}:${config.port}/health`)
+ .then((res) => res.json())
+ .then((res) => {
+ if (res.status !== 'UP') {
+ throw new Error(
+ 'Health check failed: Server responded to health check with status ' +
+ res.status,
+ );
+ }
+ })
+ .catch((err) => {
+ console.log('Health check failed:', err);
+ process.exit(1);
+ });
diff --git a/upcoming-release-notes/214.md b/upcoming-release-notes/214.md
new file mode 100644
index 0000000000..788ecee8d7
--- /dev/null
+++ b/upcoming-release-notes/214.md
@@ -0,0 +1,6 @@
+---
+category: Features
+authors: [j-f1]
+---
+
+Add a health check script (useful if running inside of a Docker container)