Coder Social home page Coder Social logo

Comments (1)

pdehaan avatar pdehaan commented on August 18, 2024

This may be a decent enough starting point:

"use strict";

const fs = require("fs");
const path = require("path");
const router = require("express").Router();

let commmit;
try {
  commit = require("git-rev-sync").short();
} catch (err) {
  // ignore
}

const { version, homepage } = require("../package.json");

const versionJsonPath = path.join(__dirname, "..", "public", "version.json");
const versionJson = {
  commit,
  source: homepage,
  version,
};

fs.writeFileSync(versionJsonPath, JSON.stringify(versionJson, null, 2) + "\n");

router.get("/__version__", (req, res) => {
  return res.sendFile(versionJsonPath);
});

router.get("/__heartbeat__", (req, res) => {
  return res.send("OK");
});

router.get("/__lbheartbeat__", (req, res) => {
  return res.send("OK");
});

module.exports = router;

This should create a ./public/version.json file which gets generated at startup and then visiting /__version__ will just return that static file. By wrapping it in a try..catch, I think it should also work if the target stage/production server doesn't have Git installed but OPs or somebody manually creates a ./public/version.json file during their build process.

We'd also need to do npm i git-rev-sync -D and add ./public/version.json to the .gitignore.

Or, I'm way off and this is just stupid. 🤷‍♀️

from blurts-server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.