Merge pull request #132 from pdehaan/issue-33

Add /__version__ route
This commit is contained in:
Danny Coates 2017-06-23 17:26:19 -07:00 committed by GitHub
commit 9bcd186d8f
5 changed files with 62 additions and 9 deletions

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
.DS_Store .DS_Store
node_modules node_modules
public/bundle.js public/bundle.js
public/version.json
static/* static/*
!static/info.txt !static/info.txt

36
package-lock.json generated
View file

@ -1336,8 +1336,7 @@
"fs.realpath": { "fs.realpath": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
"dev": true
}, },
"fsevents": { "fsevents": {
"version": "1.1.2", "version": "1.1.2",
@ -2025,6 +2024,11 @@
"integrity": "sha1-Ei4WFZHiH/TFJTAwVpPyDmOTo5g=", "integrity": "sha1-Ei4WFZHiH/TFJTAwVpPyDmOTo5g=",
"dev": true "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": { "glob": {
"version": "6.0.4", "version": "6.0.4",
"resolved": "https://registry.npmjs.org/glob/-/glob-6.0.4.tgz", "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", "resolved": "https://registry.npmjs.org/intel/-/intel-1.2.0.tgz",
"integrity": "sha1-EdEUfraz9Fgr31M3s31UFYTp5B4=" "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": { "ipaddr.js": {
"version": "1.3.0", "version": "1.3.0",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.3.0.tgz", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.3.0.tgz",
@ -3207,8 +3216,7 @@
"path-parse": { "path-parse": {
"version": "1.0.5", "version": "1.0.5",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.5.tgz", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.5.tgz",
"integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME=", "integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME="
"dev": true
}, },
"path-platform": { "path-platform": {
"version": "0.11.15", "version": "0.11.15",
@ -3620,6 +3628,11 @@
} }
} }
}, },
"rechoir": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz",
"integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q="
},
"redent": { "redent": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/redent/-/redent-1.0.0.tgz", "resolved": "https://registry.npmjs.org/redent/-/redent-1.0.0.tgz",
@ -3690,8 +3703,7 @@
"resolve": { "resolve": {
"version": "1.3.3", "version": "1.3.3",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.3.3.tgz", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.3.3.tgz",
"integrity": "sha1-ZVkHw0aahoDcLeOidaj91paR8OU=", "integrity": "sha1-ZVkHw0aahoDcLeOidaj91paR8OU="
"dev": true
}, },
"resolve-from": { "resolve-from": {
"version": "1.0.1", "version": "1.0.1",
@ -3832,6 +3844,18 @@
"integrity": "sha1-9HgZSczkAmlxJ0MOo7PFR29IF2c=", "integrity": "sha1-9HgZSczkAmlxJ0MOo7PFR29IF2c=",
"dev": true "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": { "signal-exit": {
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",

View file

@ -12,6 +12,7 @@
"cross-env": "^5.0.1", "cross-env": "^5.0.1",
"express": "^4.15.3", "express": "^4.15.3",
"express-handlebars": "^3.0.0", "express-handlebars": "^3.0.0",
"git-rev-sync": "^1.9.1",
"helmet": "^3.6.1", "helmet": "^3.6.1",
"jquery": "^3.2.1", "jquery": "^3.2.1",
"mozlog": "^2.1.1", "mozlog": "^2.1.1",
@ -38,12 +39,13 @@
"engines": { "engines": {
"node": ">=8.0.0" "node": ">=8.0.0"
}, },
"homepage": "https://github.com/mozilla/something-awesome/",
"license": "MPL-2.0", "license": "MPL-2.0",
"repository": "mozilla/something-awesome", "repository": "mozilla/something-awesome",
"scripts": { "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", "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": "npm-run-all lint:*",
"lint:css": "stylelint 'public/*.css'", "lint:css": "stylelint 'public/*.css'",
"lint:js": "eslint .", "lint:js": "eslint .",

20
scripts/version.js Executable file
View file

@ -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');

View file

@ -19,6 +19,8 @@ const mozlog = require('./log.js');
const log = mozlog('portal.server'); const log = mozlog('portal.server');
const STATIC_PATH = path.join(__dirname, '../public');
const app = express(); const app = express();
app.engine( app.engine(
@ -33,7 +35,7 @@ app.set('view engine', 'handlebars');
app.use(helmet()); app.use(helmet());
app.use(busboy()); app.use(busboy());
app.use(bodyParser.json()); app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, '../public'))); app.use(express.static(STATIC_PATH));
app.get('/', (req, res) => { app.get('/', (req, res) => {
res.render('index', { res.render('index', {
@ -164,6 +166,10 @@ app.get('/__heartbeat__', (req, res) => {
storage.ping().then(() => res.sendStatus(200), () => res.sendStatus(500)); storage.ping().then(() => res.sendStatus(200), () => res.sendStatus(500));
}); });
app.get('/__version__', (req, res) => {
res.sendFile(path.join(STATIC_PATH, 'version.json'));
});
app.listen(conf.listen_port, () => { app.listen(conf.listen_port, () => {
log.info('startServer:', `Portal app listening on port ${conf.listen_port}!`); log.info('startServer:', `Portal app listening on port ${conf.listen_port}!`);
}); });