Arundathi Patil | 85db5b0 | 2019-01-17 14:10:08 +0530 | [diff] [blame] | 1 | /* |
| 2 | ============LICENSE_START========================================== |
| 3 | =================================================================== |
| 4 | Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved. |
| 5 | =================================================================== |
| 6 | |
| 7 | Unless otherwise specified, all software contained herein is licensed |
| 8 | under the Apache License, Version 2.0 (the License); |
| 9 | you may not use this software except in compliance with the License. |
| 10 | You may obtain a copy of the License at |
| 11 | |
| 12 | http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | |
| 14 | Unless required by applicable law or agreed to in writing, software |
| 15 | distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | See the License for the specific language governing permissions and |
| 18 | limitations under the License. |
| 19 | ============LICENSE_END============================================ |
| 20 | */ |
| 21 | |
| 22 | const application = require('./dist'); |
eeginux | b9ee869 | 2019-07-04 15:01:39 +0100 | [diff] [blame] | 23 | const fs = require('fs') |
Arundathi Patil | 85db5b0 | 2019-01-17 14:10:08 +0530 | [diff] [blame] | 24 | |
| 25 | module.exports = application; |
| 26 | |
| 27 | if (require.main === module) { |
eeginux | 1094dd5 | 2020-02-18 10:54:48 +0000 | [diff] [blame] | 28 | |
| 29 | try { |
| 30 | var p12File = process.env.KEYSTORE || "aaf.p12" |
| 31 | var passwdFile = process.env.PASSPHRASE || ".enc" |
| 32 | |
| 33 | var data = fs.readFileSync(passwdFile, 'utf8') |
| 34 | var elements = data.match(/cadi_keystore_password_p12=(.*)\n/) |
| 35 | var passphrase = elements[1] |
| 36 | var p12 = fs.readFileSync(p12File) |
| 37 | } catch(e){ |
| 38 | console.error('Reading keystore error :', e) |
| 39 | process.exit(11) |
| 40 | } |
| 41 | |
Arundathi Patil | 85db5b0 | 2019-01-17 14:10:08 +0530 | [diff] [blame] | 42 | // Run the application |
| 43 | const config = { |
| 44 | rest: { |
eeginux | b9ee869 | 2019-07-04 15:01:39 +0100 | [diff] [blame] | 45 | protocol: 'https', |
eeginux | 1094dd5 | 2020-02-18 10:54:48 +0000 | [diff] [blame] | 46 | pfx: p12, |
| 47 | passphrase: passphrase, |
Arundathi Patil | 85db5b0 | 2019-01-17 14:10:08 +0530 | [diff] [blame] | 48 | port: +process.env.PORT || 3000, |
| 49 | host: process.env.HOST || 'localhost', |
| 50 | openApiSpec: { |
| 51 | // useful when used with OASGraph to locate your application |
| 52 | setServersFromRequest: true, |
| 53 | }, |
| 54 | }, |
| 55 | }; |
| 56 | application.main(config).catch(err => { |
| 57 | console.error('Cannot start the application.', err); |
| 58 | process.exit(1); |
| 59 | }); |
| 60 | } |