var a = url.resolve(origin, req.baseUrl);
var b = url.resolve(a, URL);
URL = b;
- console.log('DEBUG URL IS', URL);
} else {
protocol = protocol[1]
}
};
var projectContextUrl = function(req, url) {
- if (req.session && req.session.projectId) {
- return url.replace(/(\/api\/operational\/|\/api\/config\/|\/api\/operations\/)(.*)/, '$1project/' + req.session.projectId + '/$2');
+ //NOTE: We need to go into the sessionStore because express-session
+ // does not reliably update the session.
+ // See https://github.com/expressjs/session/issues/450
+ var projectId = (req.session &&
+ req.sessionStore &&
+ req.sessionStore.sessions &&
+ req.sessionStore.sessions[req.session.id] &&
+ JSON.parse(req.sessionStore.sessions[req.session.id])['projectId']) ||
+ (null);
+ if (projectId) {
+ return url.replace(/(\/api\/operational\/|\/api\/config\/|\/api\/operations\/)(.*)/, '$1project/' + projectId + '/$2');
}
return url;
var APIVersion = '/v2';
var configurationAPI = require('./configuration');
-function logAndReject(mesg, reject) {
+function logAndReject(mesg, reject, errCode) {
res.errorMessage = {
error: mesg
}
+ res.statusCode = errCode || constants.HTTP_RESPONSE_CODES.ERROR.BAD_REQUEST;
console.log(mesg);
reject(res);
}
username: username,
// project: req.session.projectId
};
- var successMsg = 'User =>' + username + ' successfully logged in.';
- successMsg += req.session.projectId ? 'Project =>' + req.session.projectId + ' set as default.' : '';
+ var successMsg = 'User => ' + username + ' successfully logged in.';
+ successMsg += req.session.projectId ? 'Project => ' + req.session.projectId + ' set as default.' : '';
console.log(successMsg);
status: successMsg
})
};
+
+ req.session.save(function(err) {
+ if (err) {
+ console.log('Error saving session to store', err);
+ }
+ })
+
resolve(response);
}).catch(function(error) {
return new Promise(function(resolve, reject) {
if (req.session && req.session.loggedIn == true) {
req.session.projectId = req.params.projectId;
- var successMsg = 'Added project' + req.session.projectId + ' to session' + req.sessionID;
- console.log(successMsg);
+ req.session.save(function(err) {
+ if (err) {
+ console.log('Error saving session to store', err);
+ }
+ var successMsg = 'Added project ' + req.session.projectId + ' to session ' + req.sessionID;
+ console.log(successMsg);
+
+ return resolve ({
+ statusCode: constants.HTTP_RESPONSE_CODES.SUCCESS.OK,
+ data: JSON.stringify({
+ status: successMsg
+ })
+ });
- return resolve ({
- statusCode: constants.HTTP_RESPONSE_CODES.SUCCESS.OK,
- data: JSON.stringify({
- status: successMsg
- })
+ var errorMsg = 'Session does not exist or not logged in';
+ logAndReject(errorMsg, reject, constants.HTTP_RESPONSE_CODES.ERROR.NOT_FOUND);
});
}
-
- var errorMsg = 'Session does not exist or not logged in';
- logAndReject(errorMsg, reject);
});
}
var Utils = require('utils/utils.js');
var rw = require('utils/rw.js');
var altImage = rw.getSearchParams(window.location).alt_image;
+var _ = require('lodash');
let Params = {
//Config Agent
if(self.currentAccount) {
let Account = self.getAccountFromStream(data[self.currentAccount.type].data, self.currentAccount.name);
newState.account = self.account;
- newState.account['connection-status'] = Account['connection-status']
+ newState.account['connection-status'] = Account && Account['connection-status']
}
self.setState(newState)
} catch(error) {
}
getAccountFromStream(data, name) {
let result = null;
- data.map(function(a) {
+ data && _.isArray(data) && data.map(function(a) {
if(a.name == name) {
result = a;
}
viewAccount = ({type, name}) => {
var data = null;
var accounts = null;
- if(this && this[type].length) {
+ if(this && this[type] && this[type].length) {
accounts = this[type];
data = this.getAccountFromStream(accounts, name);
if(data) {
}
generateOptionsByName(data) {
let results = [];
- if (data && data.constructor.name == "Array") {
+ if (data && _.isArray(data)) {
data.map(function(d) {
results.push({
label: d.name,
app.use(session({
secret: 'ritio rocks',
- resave: true,
+ resave: false,
saveUninitialized: true
}));
app.use(bodyParser.json());