A local-first personal finance app
[AI] Migrate health-check script to TypeScript (#8599)
Anju3ac0d7309be3
diff --git a/knip.json b/knip.jsonindex dc9fce70cd..695ed22e3b 100644--- a/knip.json+++ b/knip.json@@ -95,7 +95,7 @@"app.ts","src/app.ts","bin/**/*.js",- "src/scripts/**/*.js",+ "src/scripts/**/*.{js,ts}","src/app-*/app-*.{ts,js}"]}diff --git a/packages/sync-server/src/scripts/health-check.js b/packages/sync-server/src/scripts/health-check.tssimilarity index 54%rename from packages/sync-server/src/scripts/health-check.jsrename to packages/sync-server/src/scripts/health-check.tsindex 5b5a45dff0..1c208d5522 100644--- a/packages/sync-server/src/scripts/health-check.js+++ b/packages/sync-server/src/scripts/health-check.ts@@ -5,13 +5,28 @@ const protocol =const hostname =config.get('hostname') === '::' ? 'localhost' : config.get('hostname');+function getHealthStatus(response: unknown): string | undefined {+ if (+ typeof response === 'object' &&+ response !== null &&+ 'status' in response &&+ typeof response.status === 'string'+ ) {+ return response.status;+ }++ return undefined;+}+fetch(`${protocol}://${hostname}:${config.get('port')}/health`)- .then(res => res.json())- .then(res => {- if (res.status !== 'UP') {+ .then(response => response.json())+ .then(response => {+ const status = getHealthStatus(response);++ if (status !== 'UP') {throw new Error('Health check failed: Server responded to health check with status ' +- res.status,+ status,);}})diff --git a/packages/sync-server/vite.config.mts b/packages/sync-server/vite.config.mtsindex 89d2e663a2..f4e508e7b8 100644--- a/packages/sync-server/vite.config.mts+++ b/packages/sync-server/vite.config.mts@@ -55,7 +55,7 @@ export default defineConfig({),'scripts/health-check': path.resolve(__dirname,- 'src/scripts/health-check.js',+ 'src/scripts/health-check.ts',),},output: {diff --git a/upcoming-release-notes/migrate-health-check-typescript.md b/upcoming-release-notes/migrate-health-check-typescript.mdnew file mode 100644index 0000000000..a0d17e79a5--- /dev/null+++ b/upcoming-release-notes/migrate-health-check-typescript.md@@ -0,0 +1,6 @@+---+category: Maintenance+authors: [anjupathak03]+---++Migrate the sync-server health-check script to TypeScript