NOTICKET - Cleanup
authorKIRAN KASHALKAR <kiran.kashalkar@riftio.com>
Wed, 29 Mar 2017 20:48:56 +0000 (16:48 -0400)
committerKIRAN KASHALKAR <kiran.kashalkar@riftio.com>
Wed, 29 Mar 2017 20:48:56 +0000 (16:48 -0400)
Signed-off-by: KIRAN KASHALKAR <kiran.kashalkar@riftio.com>
skyquake/framework/core/api_utils/utils.js
skyquake/framework/core/modules/api/sessions.js
skyquake/framework/core/modules/routes/navigation.js

index 488cd9e..185c7c6 100644 (file)
@@ -51,7 +51,7 @@ var confdPort = function(api_server) {
 
 var projectContextUrl = function(req, url) {
        if (req.session && req.session.projectId) {
-               return url.replace(/(\/api\/operational\/|\/api\/config\/|\/api\/operations\/)(.*)/, '$1project/pname/$2');
+               return url.replace(/(\/api\/operational\/|\/api\/config\/|\/api\/operations\/)(.*)/, '$1project/' + req.session.projectId + '/$2');
 
        }
        return url;
@@ -69,12 +69,12 @@ var validateResponse = function(callerName, error, response, body, resolve, reje
                };
                reject(res);
                return false;
-       } else if (response.statusCode >= 400) {
+       } else if (response.statusCode >= CONSTANTS.HTTP_RESPONSE_CODES.ERROR.BAD_REQUEST) {
                console.log('Problem with "', callerName, '": ', response.statusCode, ':', body);
                res.statusCode = response.statusCode;
 
                // auth specific
-               if (response.statusCode == 401) {
+               if (response.statusCode == CONSTANTS.HTTP_RESPONSE_CODES.ERROR.UNAUTHORIZED) {
                        res.errorMessage = {
                                error: 'Authentication needed' + body
                        };
@@ -89,7 +89,7 @@ var validateResponse = function(callerName, error, response, body, resolve, reje
 
                reject(res);
                return false;
-       } else if (response.statusCode == 204) {
+       } else if (response.statusCode == CONSTANTS.HTTP_RESPONSE_CODES.SUCCESS.NO_CONTENT) {
                resolve({
                        statusCode: response.statusCode,
                        data: {}
@@ -127,12 +127,12 @@ if (process.env.LOG_REQUESTS) {
                                reject(res);
                                fs.appendFileSync(logFile, 'Request API: ' + response.request.uri.href + ' ; ' + 'Error: ' + error);
                                return false;
-                       } else if (response.statusCode >= 400) {
+                       } else if (response.statusCode >= CONSTANTS.HTTP_RESPONSE_CODES.ERROR.BAD_REQUEST) {
                                console.log('Problem with "', callerName, '": ', response.statusCode, ':', body);
                                res.statusCode = response.statusCode;
 
                                // auth specific
-                               if (response.statusCode == 401) {
+                               if (response.statusCode == CONSTANTS.HTTP_RESPONSE_CODES.ERROR.UNAUTHORIZED) {
                                        res.errorMessage = {
                                                error: 'Authentication needed' + body
                                        };
@@ -148,7 +148,7 @@ if (process.env.LOG_REQUESTS) {
                                reject(res);
                                fs.appendFileSync(logFile, 'Request API: ' + response.request.uri.href + ' ; ' + 'Error Body: ' + body);
                                return false;
-                       } else if (response.statusCode == 204) {
+                       } else if (response.statusCode == CONSTANTS.HTTP_RESPONSE_CODES.SUCCESS.NO_CONTENT) {
                                resolve();
                                fs.appendFileSync(logFile, 'Request API: ' + response.request.uri.href + ' ; ' + 'Response Body: ' + body);
                                return false;
index b609503..1be250c 100644 (file)
@@ -31,6 +31,7 @@ var sessionsAPI = {};
 var _ = require('lodash');
 var base64 = require('base-64');
 var APIVersion = '/v2';
+var configurationAPI = require('./configuration');
 
 function logAndReject(mesg, reject) {
     res.errorMessage = {
@@ -41,8 +42,10 @@ function logAndReject(mesg, reject) {
 }
 
 function logAndRedirectToLogin(mesg, res, req) {
+    var api_server = req.query['api_server'] || (req.protocol + '://' + configurationAPI.globalConfiguration.get().api_server);
+    var upload_server = req.protocol + '://' + (configurationAPI.globalConfiguration.get().upload_server || req.hostname);
     console.log(mesg);
-    res.redirect('login.html?api_server=' + req.query['api_server']);
+    res.redirect('login.html?api_server=' + api_server + '&upload_server=' + upload_server);
     res.end();
 }
 
index 9b8fbf7..7a6d99c 100644 (file)
@@ -49,7 +49,7 @@ Router.get('/', cors(), function(req, res) {
                res.redirect('/launchpad/?api_server=' + api_server + '&upload_server=' + req.protocol + '://' + (configurationAPI.globalConfiguration.get().upload_server || req.hostname));
        } else {
                console.log('Redirect to login.html');
-               res.redirect('login.html?api_server=' + api_server);
+               res.redirect('login.html?api_server=' + api_server + '&upload_server=' + req.protocol + '://' + (configurationAPI.globalConfiguration.get().upload_server || req.hostname));
        }
 });