Malek | e6c3c72 | 2018-10-16 16:44:41 +0300 | [diff] [blame^] | 1 | /* |
| 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 17 | import configData from './config.json'; |
| 18 | |
| 19 | class Configuration { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 20 | get(key) { |
| 21 | return configData[key]; |
| 22 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 23 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 24 | set(key, value) { |
| 25 | var prev = configData[key]; |
| 26 | configData[key] = value; |
| 27 | return prev; |
| 28 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 29 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 30 | setCatalogApiRoot(CatalogApiRoot) { |
| 31 | let restCatalogPrefix = CatalogApiRoot, |
| 32 | restPrefix = CatalogApiRoot.replace( |
| 33 | /\/feProxy\b[^:]*$/, |
| 34 | '/feProxy/onboarding-api' |
| 35 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 36 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 37 | this.set('restPrefix', restPrefix); |
| 38 | this.set('restCatalogPrefix', restCatalogPrefix); |
| 39 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 40 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 41 | setCatalogApiHeaders(CatalogApiHeaders) { |
| 42 | this.set('CatalogApiHeaders', CatalogApiHeaders); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 43 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 44 | let { userId: { value: UserID } = {} } = CatalogApiHeaders; |
| 45 | this.set('UserID', UserID); |
| 46 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | const configuration = new Configuration(); |
| 50 | |
| 51 | (function setDefaultRestPrefixes(configuration) { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 52 | configuration.set('restPrefix', configuration.get('defaultRestPrefix')); |
| 53 | configuration.set( |
| 54 | 'restCatalogPrefix', |
| 55 | configuration.get('defaultRestCatalogPrefix') |
| 56 | ); |
| 57 | configuration.set('appContextPath', configuration.get('appContextPath')); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 58 | })(configuration); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 59 | (function setDefaultWebsocketConfig(configuration) { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 60 | let websocketPort = configuration.get('defaultWebsocketPort'); |
| 61 | if (DEBUG) { |
| 62 | websocketPort = configuration.get('defaultDebugWebsocketPort'); |
| 63 | } |
Malek | e6c3c72 | 2018-10-16 16:44:41 +0300 | [diff] [blame^] | 64 | configuration.set( |
| 65 | 'websocketProtocol', |
| 66 | configuration.get('defaultWebsocketProtocol') |
| 67 | ); |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 68 | configuration.set('websocketPort', websocketPort); |
| 69 | configuration.set( |
| 70 | 'websocketPath', |
| 71 | configuration.get('defaultWebsocketPath') |
| 72 | ); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 73 | })(configuration); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 74 | |
Malek | e6c3c72 | 2018-10-16 16:44:41 +0300 | [diff] [blame^] | 75 | (function setDefaultNotificationsWorkerConfig(configuration) { |
| 76 | configuration.set( |
| 77 | 'notificationsWorkerUpdateMillisecond', |
| 78 | configuration.get('defaultNotificationsWorkerUpdateMillisecond') |
| 79 | ); |
| 80 | })(configuration); |
| 81 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 82 | export default configuration; |