Illyoung Choi | 59820ed | 2019-06-24 17:01:00 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2019-present Open Networking Foundation |
| 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 | |
| 17 | (function () { |
| 18 | 'use strict'; |
| 19 | |
| 20 | const argv = require('yargs').argv; |
| 21 | const path = require('path'); |
| 22 | const YamlConfig = require('node-yaml-config'); |
| 23 | const logger = require('../config/logger.js'); |
| 24 | |
| 25 | // if a config file is specified in as a CLI arguments use that one |
| 26 | const cfgFile = argv.config || 'config.yml'; |
| 27 | |
| 28 | let config; |
| 29 | try { |
| 30 | logger.log('debug', `Loading ${path.join(__dirname, cfgFile)}`); |
| 31 | config = YamlConfig.load(path.join(__dirname, cfgFile)); |
| 32 | logger.log('debug', `Parsed config: ${JSON.stringify(config)}`); |
| 33 | } |
| 34 | catch(e) { |
| 35 | logger.log('debug', `No ${cfgFile} found, using default params`); |
| 36 | } |
| 37 | |
| 38 | module.exports = { |
| 39 | service: { |
| 40 | port: (config && config.service) ? config.service.port : 3000 |
| 41 | } |
| 42 | }; |
| 43 | })(); |