Created
June 5, 2014 18:32
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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