blob: 32de7dde15abdffe0670265905606e9429c14c50 [file] [log] [blame]
Maleke6c3c722018-10-16 16:44:41 +03001/*
2* Copyright © 2018 European Support Limited
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http: //www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*/
16
Michael Landoefa037d2017-02-19 12:57:33 +020017import configData from './config.json';
18
19class Configuration {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020020 get(key) {
21 return configData[key];
22 }
Michael Landoefa037d2017-02-19 12:57:33 +020023
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020024 set(key, value) {
25 var prev = configData[key];
26 configData[key] = value;
27 return prev;
28 }
Michael Landoefa037d2017-02-19 12:57:33 +020029
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020030 setCatalogApiRoot(CatalogApiRoot) {
31 let restCatalogPrefix = CatalogApiRoot,
32 restPrefix = CatalogApiRoot.replace(
33 /\/feProxy\b[^:]*$/,
34 '/feProxy/onboarding-api'
35 );
Michael Landoefa037d2017-02-19 12:57:33 +020036
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020037 this.set('restPrefix', restPrefix);
38 this.set('restCatalogPrefix', restCatalogPrefix);
39 }
Michael Landoefa037d2017-02-19 12:57:33 +020040
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020041 setCatalogApiHeaders(CatalogApiHeaders) {
42 this.set('CatalogApiHeaders', CatalogApiHeaders);
Michael Landoefa037d2017-02-19 12:57:33 +020043
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020044 let { userId: { value: UserID } = {} } = CatalogApiHeaders;
45 this.set('UserID', UserID);
46 }
Michael Landoefa037d2017-02-19 12:57:33 +020047}
48
49const configuration = new Configuration();
50
51(function setDefaultRestPrefixes(configuration) {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020052 configuration.set('restPrefix', configuration.get('defaultRestPrefix'));
53 configuration.set(
54 'restCatalogPrefix',
55 configuration.get('defaultRestCatalogPrefix')
56 );
57 configuration.set('appContextPath', configuration.get('appContextPath'));
Michael Landoefa037d2017-02-19 12:57:33 +020058})(configuration);
talig8e9c0652017-12-20 14:30:43 +020059(function setDefaultWebsocketConfig(configuration) {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020060 let websocketPort = configuration.get('defaultWebsocketPort');
61 if (DEBUG) {
62 websocketPort = configuration.get('defaultDebugWebsocketPort');
63 }
Maleke6c3c722018-10-16 16:44:41 +030064 configuration.set(
65 'websocketProtocol',
66 configuration.get('defaultWebsocketProtocol')
67 );
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020068 configuration.set('websocketPort', websocketPort);
69 configuration.set(
70 'websocketPath',
71 configuration.get('defaultWebsocketPath')
72 );
talig8e9c0652017-12-20 14:30:43 +020073})(configuration);
Michael Landoefa037d2017-02-19 12:57:33 +020074
Maleke6c3c722018-10-16 16:44:41 +030075(function setDefaultNotificationsWorkerConfig(configuration) {
76 configuration.set(
77 'notificationsWorkerUpdateMillisecond',
78 configuration.get('defaultNotificationsWorkerUpdateMillisecond')
79 );
80})(configuration);
81
Michael Landoefa037d2017-02-19 12:57:33 +020082export default configuration;