-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.config.js
66 lines (56 loc) · 1.6 KB
/
app.config.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
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Created by avnee on 16-07-2018.
*/
'use-strict';
const config = require('config');
const mysql = require('mysql');
const AWS = require('aws-sdk');
AWS.config.region = 'ap-northeast-1';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'ap-northeast-1:863bdfec-de0f-4e9f-8749-cf7fd96ea2ff'
});
const dbConfig = config.get('rdsDB.dbConfig');
const consts = require('./routes/utils/Constants');
function getEnvType() {
return config.get("type");
}
function isProduction() {
return getEnvType() === consts.ENV_TYPE_PROD;
}
const connectionPool = mysql.createPool({
connectionLimit: 50,
host: dbConfig.host,
user: dbConfig.user,
password: dbConfig.password,
database: dbConfig.database,
timezone: 'UTC',
port: dbConfig.port,
multipleStatements: true, //To run multiple queries within the same connection callback loop
charset: 'utf8mb4_unicode_ci'
});
function getNewConnection() {
return new Promise(function (resolve, reject) {
connectionPool.getConnection(function (err, connection) {
if (err) {
reject(err);
}
else {
resolve(connection);
}
});
});
}
function disconnect(connection) {
if (connection && connection.state !== "disconnected") {
console.log('connection released');
connection.release();
}
}
module.exports = {
getEnvType: getEnvType,
isProduction: isProduction,
getNewConnection: getNewConnection,
disconnect: disconnect,
AWS: AWS,
secretkey: '5d852a5a-72c9-4943-a2a9-4ca178dda3bd'
};