Adding the server config to be read and used.

merge-requests/7/head
sinthuja 7 years ago
parent b15e532983
commit f1aa4b69ba

@ -2,5 +2,10 @@
"theme": { "theme": {
"type": "default", "type": "default",
"value": "lightBaseTheme" "value": "lightBaseTheme"
},
"config": {
"hostname": "localhost",
"httpsPort": "9443",
"apiPort": "8243"
} }
} }

@ -0,0 +1,49 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
import axios from 'axios';
import Constants from './constants';
class Configuration {
constructor() {
this.serverConfig = {};
this.hostConstants = {
baseURL: window.location.origin,
appContext: window.location.pathname.split("/")[1]
};
}
loadConfiguration(callback) {
let thisObject = this;
axios.get(thisObject.hostConstants.baseURL + '/' + thisObject.hostConstants.appContext + "/config.json").
then(function (response) {
console.log('server config was read successfully! ');
thisObject.serverConfig = response.data.config;
Constants.load();
callback();
}).catch(function (error) {
console.log('unable to load the config file!' + error);
});
}
}
export default (new Configuration());

@ -15,41 +15,47 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
import Configuration from './configuration';
'use strict'; 'use strict';
//TODO: Replace the server address with response from auth endpoint and remove hardcoded ids etc. class Constants {
export default class Constants {
static scopes = 'perm:application:get perm:application:create perm:application:update perm:application-mgt:login' + constructor() {
this.scopes = 'perm:application:get perm:application:create perm:application:update perm:application-mgt:login' +
' perm:application:delete perm:platform:add perm:platform:remove perm:roles:view perm:devices:view'; ' perm:application:delete perm:platform:add perm:platform:remove perm:roles:view perm:devices:view';
this.appManagerEndpoints = {};
this.platformManagerEndpoints = {};
this.userConstants = {};
this.defaultLocale = "en";
static appManagerEndpoints = { }
GET_ALL_APPS: 'https://localhost:8243/api/application-mgt/v1.0/applications/1.0.0/',
CREATE_APP: 'https://localhost:8243/api/application-mgt/v1.0/applications/1.0.0/', load() {
UPLOAD_IMAGE_ARTIFACTS: 'https://localhost:8243/api/application-mgt/v1.0/applications/1.0.0/upload-image-artifacts/', //+appId let apiBaseUrl = 'https://' + Configuration.serverConfig.hostname + ':' + Configuration.serverConfig.apiPort;
GET_IMAGE_ARTIFACTS: "https://localhost:8243/api/application-mgt/v1.0/applications/1.0.0/image-artifacts/" let httpBaseUrl = 'https://' + Configuration.serverConfig.hostname + ':' + Configuration.serverConfig.httpsPort;
this.appManagerEndpoints = {
GET_ALL_APPS: apiBaseUrl + '/api/application-mgt/v1.0/applications/1.0.0/',
CREATE_APP: apiBaseUrl + '/api/application-mgt/v1.0/applications/1.0.0/',
UPLOAD_IMAGE_ARTIFACTS: apiBaseUrl + '/api/application-mgt/v1.0/applications/1.0.0/upload-image-artifacts/', //+appId
GET_IMAGE_ARTIFACTS: apiBaseUrl + '/api/application-mgt/v1.0/applications/1.0.0/image-artifacts/'
}; };
static platformManagerEndpoints = { this.platformManagerEndpoints = {
CREATE_PLATFORM: 'https://localhost:8243/api/application-mgt/v1.0/platforms/1.0.0', CREATE_PLATFORM: apiBaseUrl + '/api/application-mgt/v1.0/platforms/1.0.0',
GET_ENABLED_PLATFORMS: 'https://localhost:8243/api/application-mgt/v1.0/platforms/1.0.0?status=ENABLED', GET_ENABLED_PLATFORMS: apiBaseUrl + '/api/application-mgt/v1.0/platforms/1.0.0?status=ENABLED',
GET_PLATFORM: 'https://localhost:8243/api/application-mgt/v1.0/platforms/1.0.0/' GET_PLATFORM: apiBaseUrl + '/api/application-mgt/v1.0/platforms/1.0.0/'
}; };
static userConstants = { this.userConstants = {
LOGIN_URL:"https://localhost:9443/auth/application-mgt/v1.0/auth/login", LOGIN_URL: httpBaseUrl + '/auth/application-mgt/v1.0/auth/login',
LOGOUT_URL: "https://localhost:9443/auth/application-mgt/v1.0/auth/logout", LOGOUT_URL: httpBaseUrl + '/auth/application-mgt/v1.0/auth/logout',
REFRESH_TOKEN_URL: "", REFRESH_TOKEN_URL: "",
WSO2_USER: 'wso2_user', WSO2_USER: 'wso2_user',
PARTIAL_TOKEN: 'WSO2_IOT_TOKEN' PARTIAL_TOKEN: 'WSO2_IOT_TOKEN'
}; };
static hostConstants = {
baseURL : window.location.origin,
appContext : window.location.pathname.split("/")[1]
} }
static defaultLocale = "en";
} }
export default(new Constants);

@ -57,46 +57,6 @@ class ApplicationListing extends Component {
}; };
} }
headers = [
{
data_id: "image",
data_type: "image",
sortable: false,
label: ""
},
{
data_id: "applicationName",
data_type: "string",
sortable: true,
label: "Application Name",
sort: this.sortData
},
{
data_id: "platform",
data_type: "image_array",
sortable: false,
label: "Platform"
},
{
data_id: "category",
data_type: "string",
sortable: false,
label: "Category"
},
{
data_id: "status",
data_type: "string",
sortable: false,
label: "Status"
},
{
data_id: "edit",
data_type: "button",
sortable: false,
label: ""
}
];
applications = [ applications = [
{ {

@ -24,27 +24,29 @@ import registerServiceWorker from './registerServiceWorker';
import {IntlProvider, addLocaleData, defineMessages} from 'react-intl'; import {IntlProvider, addLocaleData, defineMessages} from 'react-intl';
import Axios from 'axios'; import Axios from 'axios';
import Constants from './common/constants'; import Constants from './common/constants';
import Configuration from './common/configuration';
const possibleLocale = navigator.language.split("-")[0]; function loadStore() {
let loadLocaleFile = Axios.create({ const possibleLocale = navigator.language.split("-")[0];
baseURL: Constants.hostConstants.baseURL + "/" + Constants.hostConstants.appContext + "/locales/" let loadLocaleFile = Axios.create({
baseURL: Configuration.hostConstants.baseURL + "/" + Configuration.hostConstants.appContext + "/locales/"
+ possibleLocale + ".json" + possibleLocale + ".json"
}).get(); }).get();
/** /**
* This is the base js file of the app. All the content will be rendered in the root element. * This is the base js file of the app. All the content will be rendered in the root element.
* */ * */
loadLocaleFile.then(response => { loadLocaleFile.then(response => {
const messages = defineMessages(response.data); const messages = defineMessages(response.data);
addLocaleData(require('react-intl/locale-data/' + possibleLocale)); addLocaleData(require('react-intl/locale-data/' + possibleLocale));
ReactDOM.render(<IntlProvider locale={possibleLocale} ReactDOM.render(<IntlProvider locale={possibleLocale}
messages={messages}><Publisher/></IntlProvider>, document.getElementById('root')); messages={messages}><Publisher/></IntlProvider>, document.getElementById('root'));
registerServiceWorker(); registerServiceWorker();
}).catch(error => { }).catch(error => {
addLocaleData(require('react-intl/locale-data/' + Constants.defaultLocale)); addLocaleData(require('react-intl/locale-data/en'));
let defaultLocale = axios.create({ let defaultLocale = axios.create({
baseURL: Constants.hostConstants.baseURL + "/" + Constants.hostConstants.appContext + "/locales" baseURL: Configuration.hostConstants.baseURL + "/" + Configuration.hostConstants.appContext + "/locales"
+ Constants.defaultLocale + ".json" + Constants.defaultLocale + ".json"
}).get(); }).get();
defaultLocale.then(response => { defaultLocale.then(response => {
@ -54,4 +56,8 @@ loadLocaleFile.then(response => {
registerServiceWorker(); registerServiceWorker();
}).catch(error => { }).catch(error => {
}); });
}); });
}
Configuration.loadConfiguration(loadStore);

@ -21,7 +21,6 @@ import axios from 'axios';
import Constants from './constants'; import Constants from './constants';
//TODO: Replace the server address with response from auth endpoint and remove hardcoded ids etc.
class Configuration { class Configuration {
constructor() { constructor() {
@ -34,7 +33,9 @@ class Configuration {
loadConfiguration(callback) { loadConfiguration(callback) {
let thisObject = this; let thisObject = this;
axios.get(thisObject.hostConstants.baseURL + '/' + thisObject.hostConstants.appContext + "/config.json").then(function (response) { axios.get(thisObject.hostConstants.baseURL + '/' + thisObject.hostConstants.appContext + "/config.json").
then(function (response) {
console.log('successfully loaded the configuration!');
thisObject.serverConfig = response.data.config; thisObject.serverConfig = response.data.config;
Constants.load(); Constants.load();
callback(); callback();

Loading…
Cancel
Save