From 6f5b417dfbeddcd8d452dcf156f75c293f22b74c Mon Sep 17 00:00:00 2001 From: Gennadiy Dubina Date: Mon, 13 Feb 2017 11:01:23 +0200 Subject: [PATCH] 1. Allow to work behind port forwarding - use request's port instead of hardcoded 2. Support deployemnt separately from SO: - add api_server as app parameter - remove unnecesary using on client side Signed-off-by: Gennadiy Dubina --- skyquake/framework/utils/utils.js | 2 +- .../framework/widgets/JSONViewer/JSONViewer.scss | 1 + .../skyquakeContainerSource.js | 4 ++-- .../accounts/src/account/accountSource.js | 2 +- skyquake/plugins/composer/api/composer.js | 6 +++--- .../components/filemanager/FileManagerSource.js | 4 ++-- .../src/src/libraries/PackageManagerApi.js | 2 +- .../composer/src/src/sources/RiftHeaderSource.js | 2 +- skyquake/plugins/launchpad/src/createSource.js | 8 ++++---- .../launchpad/src/launchpadFleetSource.js | 2 +- .../src/recordViewer/recordViewSource.js | 6 +++--- .../src/topologyL2View/topologyL2Source.js | 2 +- .../launchpad/src/topologyView/topologySource.js | 2 +- .../plugins/launchpad/src/vnfr/vnfrSource.js | 2 +- skyquake/skyquake.js | 16 +++++++++++++--- 15 files changed, 36 insertions(+), 25 deletions(-) diff --git a/skyquake/framework/utils/utils.js b/skyquake/framework/utils/utils.js index 8a54ff338..e8e9ad1a9 100644 --- a/skyquake/framework/utils/utils.js +++ b/skyquake/framework/utils/utils.js @@ -189,7 +189,7 @@ Utils.setAuthentication = function(username, password, cb) { window.sessionStorage.setItem("auth", AuthBase64); self.detectInactivity(); $.ajax({ - url: '//' + window.location.hostname + ':' + NODE_PORT + '/check-auth?api_server=' + API_SERVER, + url: '//' + window.location.hostname + ':' + window.location.port + '/check-auth?api_server=' + API_SERVER, type: 'GET', beforeSend: Utils.addAuthorizationStub, success: function(data) { diff --git a/skyquake/framework/widgets/JSONViewer/JSONViewer.scss b/skyquake/framework/widgets/JSONViewer/JSONViewer.scss index 08fcefdd5..62495b2a9 100644 --- a/skyquake/framework/widgets/JSONViewer/JSONViewer.scss +++ b/skyquake/framework/widgets/JSONViewer/JSONViewer.scss @@ -1,4 +1,5 @@ .JSONViewer { + max-width: 640px; /* copied from node_modules/prismjs/themes/prismjs.css */ diff --git a/skyquake/framework/widgets/skyquake_container/skyquakeContainerSource.js b/skyquake/framework/widgets/skyquake_container/skyquakeContainerSource.js index 49356a424..ae2147a59 100644 --- a/skyquake/framework/widgets/skyquake_container/skyquakeContainerSource.js +++ b/skyquake/framework/widgets/skyquake_container/skyquakeContainerSource.js @@ -55,7 +55,7 @@ export default { remote: function(state, recordID) { return new Promise(function(resolve, reject) { $.ajax({ - url: '//' + window.location.hostname + ':' + NODE_PORT + '/api/operational/restconf-state/streams?api_server=' + API_SERVER, + url: '//' + window.location.hostname + ':' + window.location.port + '/api/operational/restconf-state/streams?api_server=' + API_SERVER, type: 'GET', beforeSend: Utils.addAuthorizationStub, success: function(data) { @@ -78,7 +78,7 @@ export default { remote: function(state, location, streamSource) { return new Promise((resolve, reject) => { $.ajax({ - url: '//' + window.location.hostname + ':' + NODE_PORT + '/socket-polling?api_server=' + API_SERVER, + url: '//' + window.location.hostname + ':' + window.location.port + '/socket-polling', type: 'POST', beforeSend: Utils.addAuthorizationStub, data: { diff --git a/skyquake/plugins/accounts/src/account/accountSource.js b/skyquake/plugins/accounts/src/account/accountSource.js index b17af40c2..08fb9f386 100644 --- a/skyquake/plugins/accounts/src/account/accountSource.js +++ b/skyquake/plugins/accounts/src/account/accountSource.js @@ -38,7 +38,7 @@ module.exports = function(Alt) { return resolve(false); } $.ajax({ - url: '/socket-polling?api_server=' + API_SERVER , + url: '/socket-polling', type: 'POST', beforeSend: Utils.addAuthorizationStub, data: { diff --git a/skyquake/plugins/composer/api/composer.js b/skyquake/plugins/composer/api/composer.js index d83311f79..ebe56360c 100644 --- a/skyquake/plugins/composer/api/composer.js +++ b/skyquake/plugins/composer/api/composer.js @@ -312,7 +312,7 @@ Composer.update = function(req) { var download_host = req.query['dev_download_server']; if (!download_host) { - download_host = api_server + ':' + utils.getPortForProtocol(req.protocol); + download_host = req.protocol + '://' + req.get('host');//api_server + ':' + utils.getPortForProtocol(req.protocol); } var input = { 'external-url': download_host + '/composer/update/' + req.file.filename, @@ -368,7 +368,7 @@ Composer.upload = function(req) { var download_host = req.query['dev_download_server']; if (!download_host) { - download_host = api_server + ':' + utils.getPortForProtocol(req.protocol); + download_host = req.protocol + '://' + req.get('host');//req.api_server + ':' + utils.getPortForProtocol(req.protocol); } return new Promise(function(resolve, reject) { @@ -425,7 +425,7 @@ Composer.addFile = function(req) { var package_type = req.query['package_type'].toUpperCase(); var package_path = req.query['package_path']; if (!download_host) { - download_host = api_server + ':' + utils.getPortForProtocol(req.protocol); + download_host = req.protocol + '://' + req.get('host');//api_server + ':' + utils.getPortForProtocol(req.protocol); } var input = { 'external-url': download_host + '/composer/upload/' + req.query['package_id'] + '/' + req.file.filename, diff --git a/skyquake/plugins/composer/src/src/components/filemanager/FileManagerSource.js b/skyquake/plugins/composer/src/src/components/filemanager/FileManagerSource.js index 95703b291..325d0263c 100644 --- a/skyquake/plugins/composer/src/src/components/filemanager/FileManagerSource.js +++ b/skyquake/plugins/composer/src/src/components/filemanager/FileManagerSource.js @@ -146,7 +146,7 @@ const FileManagerSource = { return new Promise(function(resolve, reject) { //api/operational/download-jobs/job/ $.ajax({ - url: '/socket-polling?api_server=' + API_SERVER , + url: '/socket-polling', type: 'POST', beforeSend: Utils.addAuthorizationStub, data: { @@ -171,7 +171,7 @@ const FileManagerSource = { return new Promise(function(resolve, reject) { //api/operational/download-jobs/job/ $.ajax({ - url: '/socket-polling?api_server=' + API_SERVER , + url: '/socket-polling', type: 'POST', beforeSend: Utils.addAuthorizationStub, data: { diff --git a/skyquake/plugins/composer/src/src/libraries/PackageManagerApi.js b/skyquake/plugins/composer/src/src/libraries/PackageManagerApi.js index 6b8862c94..69fa4d66e 100644 --- a/skyquake/plugins/composer/src/src/libraries/PackageManagerApi.js +++ b/skyquake/plugins/composer/src/src/libraries/PackageManagerApi.js @@ -76,7 +76,7 @@ export default class PackageManager { } new Promise(function(resolve, reject) { $.ajax({ - url: '/socket-polling?api_server=' + API_SERVER , + url: '/socket-polling', type: 'POST', beforeSend: Utils.addAuthorizationStub, data: { diff --git a/skyquake/plugins/composer/src/src/sources/RiftHeaderSource.js b/skyquake/plugins/composer/src/src/sources/RiftHeaderSource.js index e479d33fc..3e613879a 100644 --- a/skyquake/plugins/composer/src/src/sources/RiftHeaderSource.js +++ b/skyquake/plugins/composer/src/src/sources/RiftHeaderSource.js @@ -31,7 +31,7 @@ function getApiServerOrigin() { } function ajaxRequest(path, catalogPackage, resolve, reject, method = 'GET') { $.ajax({ - url: '//' + window.location.hostname + ':' + getApiServerOrigin() + path, + url: '//' + window.location.hostname + ':' + window.location.port + path, type: method, beforeSend: utils.addAuthorizationStub, dataType: 'json', diff --git a/skyquake/plugins/launchpad/src/createSource.js b/skyquake/plugins/launchpad/src/createSource.js index d9271d630..6c837a7f9 100644 --- a/skyquake/plugins/launchpad/src/createSource.js +++ b/skyquake/plugins/launchpad/src/createSource.js @@ -29,7 +29,7 @@ module.exports = { remote: function() { return new Promise(function(resolve, reject) { $.ajax({ - url: '//' + window.location.hostname + ':' + NODE_PORT + '/api/launchpad/network-service?api_server=' + API_SERVER, + url: '//' + window.location.hostname + ':' + window.location.port + '/api/launchpad/network-service?api_server=' + API_SERVER, type: 'GET', beforeSend: Utils.addAuthorizationStub, success: function(data) { @@ -46,7 +46,7 @@ module.exports = { return { remote: function(state, environment) { return $.ajax({ - url: '//' + window.location.hostname + ':' + NODE_PORT + '/api/launchpad/environment?api_server=' + API_SERVER, + url: '//' + window.location.hostname + ':' + window.location.port + '/api/launchpad/environment?api_server=' + API_SERVER, type: 'POST', beforeSend: Utils.addAuthorizationStub, dataType: 'json', @@ -65,7 +65,7 @@ module.exports = { remote: function() { return new Promise(function(resolve, reject) { $.ajax({ - url: '//' + window.location.hostname + ':' + NODE_PORT + '/api/launchpad/pools?api_server=' + API_SERVER, + url: '//' + window.location.hostname + ':' + window.location.port + '/api/launchpad/pools?api_server=' + API_SERVER, type: 'GET', beforeSend: Utils.addAuthorizationStub, success: function(data) { @@ -83,7 +83,7 @@ module.exports = { remote: function() { return new Promise(function(resolve, reject) { $.ajax({ - url: '//' + window.location.hostname + ':' + NODE_PORT + '/api/launchpad/sla-params?api_server=' + API_SERVER, + url: '//' + window.location.hostname + ':' + window.location.port + '/api/launchpad/sla-params?api_server=' + API_SERVER, type: 'GET', beforeSend: Utils.addAuthorizationStub, success: function(data) { diff --git a/skyquake/plugins/launchpad/src/launchpadFleetSource.js b/skyquake/plugins/launchpad/src/launchpadFleetSource.js index 0e9b34e9b..cde71160f 100644 --- a/skyquake/plugins/launchpad/src/launchpadFleetSource.js +++ b/skyquake/plugins/launchpad/src/launchpadFleetSource.js @@ -106,7 +106,7 @@ module.exports = function(Alt) { return resolve(false); } $.ajax({ - url: '/socket-polling?api_server=' + API_SERVER , + url: '/socket-polling', type: 'POST', beforeSend: Utils.addAuthorizationStub, data: { diff --git a/skyquake/plugins/launchpad/src/recordViewer/recordViewSource.js b/skyquake/plugins/launchpad/src/recordViewer/recordViewSource.js index 49c312288..a3b2d6796 100644 --- a/skyquake/plugins/launchpad/src/recordViewer/recordViewSource.js +++ b/skyquake/plugins/launchpad/src/recordViewer/recordViewSource.js @@ -94,7 +94,7 @@ export default { return new Promise(function(resolve, reject) { console.log('Getting NSR Socket'); $.ajax({ - url: '/socket-polling?api_server=' + API_SERVER, + url: '/socket-polling', type: 'POST', beforeSend: Utils.addAuthorizationStub, data: { @@ -117,7 +117,7 @@ export default { return new Promise(function(resolve, reject) { console.log('Getting Job Socket'); $.ajax({ - url: '/socket-polling?api_server=' + API_SERVER, + url: '/socket-polling', type: 'POST', beforeSend: Utils.addAuthorizationStub, data: { @@ -139,7 +139,7 @@ export default { return new Promise(function(resolve, reject) { console.log('Getting VNFR Socket for: ' + state.recordID); $.ajax({ - url: '/socket-polling?api_server=' + API_SERVER, + url: '/socket-polling', type: 'POST', beforeSend: Utils.addAuthorizationStub, data: { diff --git a/skyquake/plugins/launchpad/src/topologyL2View/topologyL2Source.js b/skyquake/plugins/launchpad/src/topologyL2View/topologyL2Source.js index e927984a7..fd38d84da 100644 --- a/skyquake/plugins/launchpad/src/topologyL2View/topologyL2Source.js +++ b/skyquake/plugins/launchpad/src/topologyL2View/topologyL2Source.js @@ -41,7 +41,7 @@ export default { return resolve(false); } $.ajax({ - url: '/socket-polling?api_server=' + API_SERVER , + url: '/socket-polling', type: 'POST', beforeSend: Utils.addAuthorizationStub, data: { diff --git a/skyquake/plugins/launchpad/src/topologyView/topologySource.js b/skyquake/plugins/launchpad/src/topologyView/topologySource.js index 23db98219..04e1c66b8 100644 --- a/skyquake/plugins/launchpad/src/topologyView/topologySource.js +++ b/skyquake/plugins/launchpad/src/topologyView/topologySource.js @@ -42,7 +42,7 @@ export default { return resolve(false); } $.ajax({ - url: '/socket-polling?api_server=' + API_SERVER , + url: '/socket-polling', type: 'POST', beforeSend: Utils.addAuthorizationStub, data: { diff --git a/skyquake/plugins/launchpad/src/vnfr/vnfrSource.js b/skyquake/plugins/launchpad/src/vnfr/vnfrSource.js index bcb825273..782f32263 100644 --- a/skyquake/plugins/launchpad/src/vnfr/vnfrSource.js +++ b/skyquake/plugins/launchpad/src/vnfr/vnfrSource.js @@ -42,7 +42,7 @@ export default { } console.log(nsr_id) $.ajax({ - url: '//' + window.location.hostname + ':' + NODE_PORT + '/socket-polling?api_server=' + API_SERVER, + url: '//' + window.location.hostname + ':' + window.location.port + '/socket-polling', type: 'POST', beforeSend: Utils.addAuthorizationStub, data: { diff --git a/skyquake/skyquake.js b/skyquake/skyquake.js index b9af78aff..726757fbb 100644 --- a/skyquake/skyquake.js +++ b/skyquake/skyquake.js @@ -83,6 +83,9 @@ if (cluster.isMaster && clusteredLaunch) { var sslOptions = null; + var apiServer = argv['api-server'] ? argv['api-server'] : 'localhost'; + var uploadServer = argv['upload-server'] ? argv['upload-server'] : null; + try { if (argv['enable-https']) { var keyFilePath = argv['keyfile-path']; @@ -194,9 +197,16 @@ if (cluster.isMaster && clusteredLaunch) { app.use(inactivity_routes); // Configure global config with ssl enabled/disabled - configurationAPI.globalConfiguration.update({ - ssl_enabled: httpsConfigured - }); + var globalConfig = { + ssl_enabled: httpsConfigured, + api_server: apiServer + }; + + if (uploadServer) { + globalConfig.upload_server = uploadServer; + } + + configurationAPI.globalConfiguration.update(globalConfig); // Configure configuration route(s) app.use(configuration_routes); -- 2.17.1