Matteo Scandolo | bd13aab | 2017-08-08 13:05:24 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
Matteo Scandolo | e3ed016 | 2016-12-01 10:09:12 -0800 | [diff] [blame] | 19 | (function () { |
| 20 | 'use strict'; |
| 21 | |
| 22 | // NOTE do we still need CLI args? |
| 23 | // Won't be better to use NODE_ENV and the native node-yaml-config feature |
| 24 | |
| 25 | const argv = require('yargs').argv; |
| 26 | const path = require('path'); |
| 27 | const yaml_config = require('node-yaml-config'); |
| 28 | const logger = require('../config/logger.js'); |
| 29 | |
| 30 | // if a config file is specified in as a CLI arguments use that one |
| 31 | const cfgFile = argv.config || 'config.yml'; |
| 32 | |
| 33 | let config; |
| 34 | try { |
| 35 | logger.log('debug', `Loading ${cfgFile}`); |
| 36 | config = yaml_config.load(path.join(__dirname, cfgFile)); |
| 37 | } |
| 38 | catch(e) { |
| 39 | logger.log('debug', `No ${cfgFile} found, using default params`); |
| 40 | } |
| 41 | |
| 42 | module.exports = { |
Matteo Scandolo | e3ed016 | 2016-12-01 10:09:12 -0800 | [diff] [blame] | 43 | redis: { |
| 44 | host: (config && config.redis) ? config.redis.host : 'redis', |
| 45 | port: (config && config.redis) ? config.redis.port : 6379 |
| 46 | }, |
| 47 | gateway: { |
| 48 | port: (config && config.gateway) ? config.gateway.port : 3000 |
| 49 | } |
| 50 | }; |
| 51 | })(); |