From 2b01bb75dc493fbb84b218a89991663f31fa48dd Mon Sep 17 00:00:00 2001 From: Peter deHaan Date: Fri, 23 Jun 2017 11:29:45 -0700 Subject: [PATCH 1/2] Add /__version__ route --- package-lock.json | 36 ++++++++++++++++++++++++++++++------ package.json | 2 ++ server/portal_server.js | 11 +++++++++++ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6c2025ca..2050aba6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1336,8 +1336,7 @@ "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, "fsevents": { "version": "1.1.2", @@ -2025,6 +2024,11 @@ "integrity": "sha1-Ei4WFZHiH/TFJTAwVpPyDmOTo5g=", "dev": true }, + "git-rev-sync": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/git-rev-sync/-/git-rev-sync-1.9.1.tgz", + "integrity": "sha1-oMLj3TkqvPa3aWLif8dfsyI0Sc4=" + }, "glob": { "version": "6.0.4", "resolved": "https://registry.npmjs.org/glob/-/glob-6.0.4.tgz", @@ -2280,6 +2284,11 @@ "resolved": "https://registry.npmjs.org/intel/-/intel-1.2.0.tgz", "integrity": "sha1-EdEUfraz9Fgr31M3s31UFYTp5B4=" }, + "interpret": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.0.3.tgz", + "integrity": "sha1-y8NcYu7uc/Gat7EKgBURQBr8D5A=" + }, "ipaddr.js": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.3.0.tgz", @@ -3197,8 +3206,7 @@ "path-parse": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.5.tgz", - "integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME=", - "dev": true + "integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME=" }, "path-platform": { "version": "0.11.15", @@ -3593,6 +3601,11 @@ } } }, + "rechoir": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", + "integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=" + }, "redent": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/redent/-/redent-1.0.0.tgz", @@ -3663,8 +3676,7 @@ "resolve": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.3.3.tgz", - "integrity": "sha1-ZVkHw0aahoDcLeOidaj91paR8OU=", - "dev": true + "integrity": "sha1-ZVkHw0aahoDcLeOidaj91paR8OU=" }, "resolve-from": { "version": "1.0.1", @@ -3805,6 +3817,18 @@ "integrity": "sha1-9HgZSczkAmlxJ0MOo7PFR29IF2c=", "dev": true }, + "shelljs": { + "version": "0.7.7", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.7.7.tgz", + "integrity": "sha1-svXHfvlxSPS09uImguELuoZnz/E=", + "dependencies": { + "glob": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", + "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==" + } + } + }, "signal-exit": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", diff --git a/package.json b/package.json index cab3eba7..f9fc70a2 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "cross-env": "^5.0.1", "express": "^4.15.3", "express-handlebars": "^3.0.0", + "git-rev-sync": "1.9.1", "helmet": "^3.6.1", "jquery": "^3.2.1", "mozlog": "^2.1.1", @@ -37,6 +38,7 @@ "engines": { "node": ">=8.0.0" }, + "homepage": "https://github.com/mozilla/something-awesome/", "license": "MPL-2.0", "repository": "mozilla/something-awesome", "scripts": { diff --git a/server/portal_server.js b/server/portal_server.js index acf47b82..764892c1 100644 --- a/server/portal_server.js +++ b/server/portal_server.js @@ -7,6 +7,9 @@ const helmet = require('helmet'); const bytes = require('bytes'); const conf = require('./config.js'); const storage = require('./storage.js'); +const pkg = require('../package.json'); + +const gitSHA = require('git-rev-sync').short(); const notLocalHost = conf.notLocalHost; @@ -150,6 +153,14 @@ app.get('/__lbheartbeat__', (req, res) => { res.sendStatus(200); }); +app.get('/__version__', (req, res) => { + res.json({ + commit: gitSHA, + source: pkg.homepage, + version: pkg.version + }); +}); + app.listen(conf.listen_port, () => { log.info('startServer:', `Portal app listening on port ${conf.listen_port}!`); }); From 314e756ef1bd7be3aac244c604e24cca027f52ae Mon Sep 17 00:00:00 2001 From: Peter deHaan Date: Fri, 23 Jun 2017 16:53:17 -0700 Subject: [PATCH 2/2] Move __version__ to a script --- .gitignore | 1 + package.json | 6 +++--- scripts/version.js | 20 ++++++++++++++++++++ server/portal_server.js | 14 ++++---------- 4 files changed, 28 insertions(+), 13 deletions(-) create mode 100755 scripts/version.js diff --git a/.gitignore b/.gitignore index 2ff1484e..6bd525a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_Store node_modules public/bundle.js +public/version.json static/* !static/info.txt diff --git a/package.json b/package.json index f9fc70a2..340e7b3b 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "cross-env": "^5.0.1", "express": "^4.15.3", "express-handlebars": "^3.0.0", - "git-rev-sync": "1.9.1", + "git-rev-sync": "^1.9.1", "helmet": "^3.6.1", "jquery": "^3.2.1", "mozlog": "^2.1.1", @@ -42,9 +42,9 @@ "license": "MPL-2.0", "repository": "mozilla/something-awesome", "scripts": { - "bundle": "browserify frontend/src/main.js | uglifyjs > public/bundle.js", + "bundle": "browserify frontend/src/main.js | uglifyjs > public/bundle.js && node scripts/version", "dev": "watchify frontend/src/main.js -o public/bundle.js -d | node server/portal_server", - "format": "prettier 'frontend/src/*.js' 'public/*.css' 'server/*.js' 'test/*.js' --single-quote --write", + "format": "prettier '{frontend/src/,scripts/,server/,test/}*.js' 'public/*.css' --single-quote --write", "lint": "npm-run-all lint:*", "lint:css": "stylelint 'public/*.css'", "lint:js": "eslint .", diff --git a/scripts/version.js b/scripts/version.js new file mode 100755 index 00000000..e39e7a1a --- /dev/null +++ b/scripts/version.js @@ -0,0 +1,20 @@ +const fs = require('fs'); +const path = require('path'); +const pkg = require('../package.json'); + +let commit; + +try { + commit = require('git-rev-sync').short(); +} catch (err) { + // Whatever... +} + +const filename = path.join(__dirname, '..', 'public', 'version.json'); +const filedata = { + commit, + source: pkg.homepage, + version: pkg.version +}; + +fs.writeFileSync(filename, JSON.stringify(filedata, null, 2) + '\n'); diff --git a/server/portal_server.js b/server/portal_server.js index 764892c1..4da2c095 100644 --- a/server/portal_server.js +++ b/server/portal_server.js @@ -7,9 +7,6 @@ const helmet = require('helmet'); const bytes = require('bytes'); const conf = require('./config.js'); const storage = require('./storage.js'); -const pkg = require('../package.json'); - -const gitSHA = require('git-rev-sync').short(); const notLocalHost = conf.notLocalHost; @@ -17,6 +14,8 @@ const mozlog = require('./log.js'); const log = mozlog('portal.server'); +const STATIC_PATH = path.join(__dirname, '../public'); + const app = express(); app.engine('handlebars', exphbs({ @@ -28,8 +27,7 @@ app.set('view engine', 'handlebars'); app.use(helmet()); app.use(busboy()); app.use(bodyParser.json()); -app.use(express.static(path.join(__dirname, '../public'))); - +app.use(express.static(STATIC_PATH)); app.get('/', (req, res) => { res.render('index', { @@ -154,11 +152,7 @@ app.get('/__lbheartbeat__', (req, res) => { }); app.get('/__version__', (req, res) => { - res.json({ - commit: gitSHA, - source: pkg.homepage, - version: pkg.version - }); + res.sendFile(path.join(STATIC_PATH, 'version.json')); }); app.listen(conf.listen_port, () => {