add version endpoint and version logging
Node.js CI / build (push) Successful in 3m22s

This commit is contained in:
2025-07-17 14:44:26 +02:00
parent fc3a4bb7ba
commit fcd08cbaac
5 changed files with 33 additions and 1 deletions
+1
View File
@@ -4,6 +4,7 @@ Dockerfile
.dockerignore
README.md
LICENSE
VERSION
node_modules/
coverge/
# dotenv environment variable files
+2
View File
@@ -1,8 +1,10 @@
const router = require('express').Router();
const badgeRouter = require('./badge');
const tagRouter = require('./tag');
const versionRouter = require('./version');
router.use(badgeRouter);
router.use(tagRouter);
router.use(versionRouter);
module.exports = { router };
+8
View File
@@ -0,0 +1,8 @@
const router = require('express').Router();
const version = require('../lib/version').version();
router.get('/version', (req, res) => {
res.json({ badgedexVersion: version });
});
module.exports = router;
+3 -1
View File
@@ -2,6 +2,7 @@ const express = require('express');
const helmet = require('helmet');
const app = express();
const PORT = process.env.PORT || 3000;
const version = require('./lib/version').version();
const api = require('./api');
@@ -12,5 +13,6 @@ app.use(helmet({
app.use('/', api.router);
app.listen(PORT, () => {
console.log(`🚀 Badge API running at http://localhost:${PORT}/`);
console.log(`[ ${new Date()} ] [ 🚀 BadgeDex version: ${version} ]`);
console.log(`[ ${new Date()} ] [ 🚀 BadgeDex API running at http://localhost:${PORT}/ ]`);
});
+19
View File
@@ -0,0 +1,19 @@
const fs = require('fs');
const version = () => {
if (process.env.VERSION) {
return process.env.VERSION;
}
// Fallback to reading from a VERSION file
const versionPath = require('path').resolve(__dirname, '../../VERSION');
if (!fs.existsSync(versionPath)) {
throw new Error('VERSION file not found');
}
// Read the version from the VERSION file
const fileVersion = fs.readFileSync(versionPath, 'utf8').trim();
return fileVersion;
}
module.exports = { version };