From c0e166509aa860fdd225a97ffee76cb9e33535ba Mon Sep 17 00:00:00 2001 From: Martin Danielsson Date: Thu, 8 Dec 2016 10:59:43 +0100 Subject: [PATCH] Sanity checks for config hash and versioning Implementation of Haufe-Lexware/wicked.haufe.io#36 and Haufe-Lexware/wicked.haufe.io#38 in the portal. --- app.js | 3 ++- bin/www | 5 ++++- package.json | 6 +++--- routes/utils.js | 13 ++++++++----- views/error_428.jade | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 views/error_428.jade diff --git a/app.js b/app.js index a02a34f..6245e82 100644 --- a/app.js +++ b/app.js @@ -210,7 +210,7 @@ app.initialize = function (done) { // development error handler // will print stacktrace - if ((app.get('env') === 'development')) { // TODO: || !process.env.WICKED_IN_DOCKER) { + if (wicked.isDevelopmentMode()) { app.use(function (err, req, res, next) { debug(err); res.status(err.status || 500); @@ -245,6 +245,7 @@ app.initialize = function (done) { switch (status) { case 403: errorTemplate = 'error_403'; break; case 404: errorTemplate = 'error_404'; break; + case 428: errorTemplate = 'error_428'; break; } res.render(errorTemplate, { diff --git a/bin/www b/bin/www index d65e647..8a58cc9 100755 --- a/bin/www +++ b/bin/www @@ -41,7 +41,10 @@ server.on('listening', onListening); // Wait for Portal API to be available debug('Waiting for API to be available.'); app.initState = 'Waiting for API...'; -wicked.initialize(function (err) { +wicked.initialize({ + userAgentName: 'wicked.portal', + userAgentVersion: utils.getVersion() +}, function (err) { if (err) { console.error(err); throw Error('Could not retrieve globals from API! API not running?'); diff --git a/package.json b/package.json index ab02ae5..bf160b9 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "0.10.1", + "version": "0.11.0", "private": true, "dependencies": { "async": "2.0.1", @@ -29,7 +29,7 @@ "session-file-store": "0.2.0", "swagger-ui": "2.1.5", "tmp": "0.0.30", - "wicked-sdk": "^0.10.8" + "wicked-sdk": "^0.11.1" }, "scripts": { "start": "node ./bin/www" @@ -39,4 +39,4 @@ "esversion": 6 }, "name": "portal" -} +} \ No newline at end of file diff --git a/routes/utils.js b/routes/utils.js index f909184..58bfab2 100644 --- a/routes/utils.js +++ b/routes/utils.js @@ -4,6 +4,7 @@ var request = require('request'); var debug = require('debug')('portal:utils'); var fs = require('fs'); var path = require('path'); +var wicked = require('wicked-sdk'); var utils = function () { }; @@ -22,17 +23,19 @@ utils.getLoggedInUserEmail = function (req) { }; function makeHeaders(req, userId) { + var headers = { + 'User-Agent': 'wicked.portal/' + utils.getVersion(), + 'X-Config-Hash': wicked.getConfigHash(), + 'Correlation-Id': req.correlationId, + }; if (!userId) { - var headers = { 'Correlation-Id': req.correlationId }; var loggedInUserId = utils.getLoggedInUserId(req); if (loggedInUserId) headers['X-UserId'] = loggedInUserId; return headers; } - return { - 'X-UserId': userId, - 'Correlation-Id': req.correlationId - }; + headers['X-UserId'] = userId; + return headers; } utils.get = function (req, uri, callback) { diff --git a/views/error_428.jade b/views/error_428.jade new file mode 100644 index 0000000..e0e3f86 --- /dev/null +++ b/views/error_428.jade @@ -0,0 +1,37 @@ +extends layout + +block content + + .jumbotron.wicked-error-title + .container.wicked-title-container + h1 Configuration Mismatch + + h2 Status Code: #{error.status} + + p= message + + a(class='btn btn-lg btn-warning' onclick='window.history.back();') Go back » + + .container.wicked-container + + img(src='/images/wicked-256.png').center-block + + br + br + + h4. + The configuration has changed, or the Portal runs a different version of wicked.haufe.io than the underlying API. + + p. + Please check back in a minute. This may be intended behavior, and the portal will restart shortly. + If the problem persists, please notify the maintainer of this API Portal. + + br + br + br + + p. + Correlation ID: #{correlationId} + + if error.stack + pre #{error.stack}