Skip to content

Commit e2be223

Browse files
Expose application version in API
1 parent 0f055c7 commit e2be223

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/server.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ const fs = require('fs/promises');
22
const crypto = require('crypto');
33
const http = require('http');
44
const path = require('path');
5+
const packageJson = require('../package.json');
56

67
const ROOT_DIR = path.resolve(__dirname, '..');
78
const PUBLIC_DIR = path.join(ROOT_DIR, 'public');
89
const DATA_DIR = path.join(ROOT_DIR, 'data');
910
const PORT = Number(process.env.APP_PORT || 8080);
11+
const APP_VERSION = packageJson.version || '0.0.0';
1012
const ARANGO_URL = (process.env.ARANGO_URL || 'http://127.0.0.1:8529').replace(/\/$/, '');
1113
const ARANGO_DB = process.env.ARANGO_DB || 'tables_forms_app';
1214
const ARANGO_USER = process.env.ARANGO_USER || 'root';
@@ -1561,14 +1563,19 @@ async function handleApi(req, res, pathname) {
15611563
if (req.method === 'GET' && pathname === '/api/health') {
15621564
try {
15631565
await ensureDbReady();
1564-
sendJson(res, 200, { ok: true, db: ARANGO_DB });
1566+
sendJson(res, 200, { ok: true, db: ARANGO_DB, version: APP_VERSION });
15651567
} catch (err) {
15661568
console.error('Health check failed:', err);
1567-
sendJson(res, 503, { ok: false, error: 'Database is not available' });
1569+
sendJson(res, 503, { ok: false, error: 'Database is not available', version: APP_VERSION });
15681570
}
15691571
return;
15701572
}
15711573

1574+
if (req.method === 'GET' && pathname === '/api/version') {
1575+
sendJson(res, 200, { version: APP_VERSION });
1576+
return;
1577+
}
1578+
15721579
if (req.method === 'GET' && pathname === '/api/auth/me') {
15731580
const session = requireSession(req, res);
15741581
if (!session) return;

0 commit comments

Comments
 (0)