Skip to content

Commit

Permalink
Sanity checks for config hash and versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
DonMartin76 committed Dec 8, 2016
1 parent 45ff7b2 commit c0e1665
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 10 deletions.
3 changes: 2 additions & 1 deletion app.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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, {
Expand Down
5 changes: 4 additions & 1 deletion bin/www
Expand Up @@ -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?');
Expand Down
6 changes: 3 additions & 3 deletions package.json
@@ -1,5 +1,5 @@
{
"version": "0.10.1",
"version": "0.11.0",
"private": true,
"dependencies": {
"async": "2.0.1",
Expand Down Expand Up @@ -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"
Expand All @@ -39,4 +39,4 @@
"esversion": 6
},
"name": "portal"
}
}
13 changes: 8 additions & 5 deletions routes/utils.js
Expand Up @@ -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 () { };

Expand All @@ -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) {
Expand Down
37 changes: 37 additions & 0 deletions 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 &raquo

.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: <code>#{correlationId}</code>

if error.stack
pre #{error.stack}

0 comments on commit c0e1665

Please sign in to comment.