diff --git a/.dockerignore b/.dockerignore index 5312275..f3699d0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,6 +4,7 @@ Dockerfile .dockerignore README.md LICENSE +VERSION node_modules/ coverge/ # dotenv environment variable files diff --git a/src/api/index.js b/src/api/index.js index d9a9460..85c4d10 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -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 }; \ No newline at end of file diff --git a/src/api/version.js b/src/api/version.js new file mode 100644 index 0000000..8192e33 --- /dev/null +++ b/src/api/version.js @@ -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; \ No newline at end of file diff --git a/src/index.js b/src/index.js index 2bb1926..2557919 100644 --- a/src/index.js +++ b/src/index.js @@ -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}/ ]`); }); diff --git a/src/lib/version.js b/src/lib/version.js new file mode 100644 index 0000000..3d519af --- /dev/null +++ b/src/lib/version.js @@ -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 }; \ No newline at end of file