1
0
Fork 0
nodejs-backend-template/server/api/public/controllers/version.js

34 lines
1.3 KiB
JavaScript

const Joi = require(`joi`);
const fs = require('fs');
const util = require("util");
const readFile = util.promisify(fs.readFile);
/**
* @module An object representing the HTTP GET method for obtaining information about the application version.
* @type {Object}
* @property {string} method - HTTP method (get).
* @property {string} path - The path to process the request ("/version").
* @property {Joi.ObjectSchema} validationSchema - Input validation scheme.
* @property {Array} middlewares - Middlewares that can be applied to the request processing (empty array).
* @property {Function} handler - The function that handles the request to get information about the application version.
* @async
* @param {Object} req - The request object.
* @param {Object} res - Response object.
* @returns {Object} - An object that contains information about the version of the application.
* @throws {Error} - An exception if an error occurred while processing the request.
*/
module.exports = {
method: `get`,
path: `/version`,
validationSchema: Joi.object({}),
middlewares: [],
handler: async function (req, res) {
const buildFile = await readFile('build.json');
const build = JSON.parse(buildFile);
return res.status(200).json({
"buildChecksum": build.buildChecksum,
"buildTime": build.buildTime,
});
}
};