Skip to content

Instantly share code, notes, and snippets.

@dylants
Created June 5, 2014 18:32
Show Gist options
  • Save dylants/64ca92f3c94d82f775b1 to your computer and use it in GitHub Desktop.
Save dylants/64ca92f3c94d82f775b1 to your computer and use it in GitHub Desktop.
Display a version (doubles as a health check) for the app, based on the latest Git commit
/*
* package.json
*/
{
"name": "app-name",
"version": "0.1.0",
"scripts": {
"prestart": "git rev-parse HEAD > ./BUILD",
"start": "node app.js"
}
}
/*
* Route index.js
*/
"use strict";
// needed for the version health check
var pkg = require("../package.json"),
fs = require("fs"),
build = fs.readFileSync("BUILD", "utf8").trim();
module.exports.endpoints = [
// version health check
{ method: "GET", path: "/api/version", handler: function(request, reply) {
reply({
name: pkg.name,
version: pkg.version,
build: build
});
}}
];
/*
* And ignore the BUILD file in .gitignore
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment