-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdb-factory.js
53 lines (47 loc) · 1.87 KB
/
db-factory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const { MongoClient } = require('mongodb');
const JWT = require('jsonwebtoken');
const log4js = require('log4js');
const config = require('./config');
const httpClient = require('./http-client');
const LOGGER_NAME = config.isK8sEnv() ? `[${config.hostname}] [FAAS v${config.imageTag}]` : `[FAAS v${config.imageTag}]`;
const logger = log4js.getLogger(LOGGER_NAME);
const token = JWT.sign({ name: 'B2B-MANAGER', _id: 'admin', isSuperAdmin: true }, config.RBAC_JWT_KEY, {});
// For threads to pick txnId and user headers
global.userHeader = 'user';
global.txnIdHeader = 'txnid';
global.loggerName = LOGGER_NAME;
global.trueBooleanValues = ['y', 'yes', 'true', '1'];
global.falseBooleanValues = ['n', 'no', 'false', '0'];
global.BM_TOKEN = token;
(async () => {
try {
logger.trace(config.mongoUrl, config.mongoAppCenterOptions, config.appDB);
const client = await MongoClient.connect(config.mongoUrl, config.mongoAppCenterOptions);
logger.info('Connected to ', config.appDB);
const appcenterDB = client.db(config.appDB);
global.appcenterDB = appcenterDB;
} catch(err) {
logger.error(err);
process.exit(0);
}
// if (process.env.NODE_ENV !== 'production') {
// logger.info(`NODE_ENV is ${process.env.NODE_ENV}. Won't call BM API.`);
// } else {
// try {
// let b2bBaseURL = config.baseUrlBM + '/' + config.app + '/faas/utils/' + config.faasId + '/init';
// logger.debug(`BM API Call :: ${config.baseUrlBM + '/' + config.app + '/faas/utils/' + config.faasId + '/init'}`);
// const resp = await httpClient.request({
// method: 'PUT',
// url: b2bBaseURL,
// headers: {
// 'Content-Type': 'application/json'
// }
// });
// logger.debug(`BM API Call status :: ${resp.statusCode}`);
// logger.trace(`BM API Call response body :: ${resp.body}`);
// } catch (err) {
// logger.error('Unable to inform B2B Manager');
// logger.error(err);
// }
// }
})();