-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.ts
137 lines (121 loc) · 3.78 KB
/
config.ts
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*eslint no-useless-escape: "off"*/
import { execSync } from 'child_process';
import dotenv from 'dotenv';
/**
* @description Get Package Version
* @private
* @returns {string}
*/
const packageVersionGetter = (): string => {
const version_buffer = execSync(
`echo $(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]')`,
);
return version_buffer ? version_buffer.toString() : '1.0.1';
};
/**
* @description Get Package Name
* @private
* @returns {string}
*/
const packageNameGetter = (): string => {
const name_buffer = execSync(
`echo $(cat package.json | grep name | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]')`,
);
return name_buffer ? name_buffer.toString() : 'one-piece-user';
};
/**
* @description Get Package Description
* @private
* @returns {string}
*/
const packageDescriptionGetter = (): string => {
const description_buffer = execSync(
`echo $(cat package.json | grep description | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]')`,
);
return description_buffer
? description_buffer.toString()
: 'service evaluate open api';
};
// load config
dotenv.config();
const env = process.env.NODE_ENV || 'development';
const configs = {
base: {
ENV: env,
DEV: env === 'development',
// Pkg Base
NAME: packageNameGetter(),
DESCRIPTION: packageDescriptionGetter(),
// API
PREFIX: process.env.APPAPIPREFIX || '',
VERSION: packageVersionGetter(),
API_EXPLORER_PATH: process.env.APPAPIEXPLORERPATH || '',
// Server Setting
PROTOCL: process.env.APPPROTOCOL || 'http',
HOST: process.env.APPHOST || 'localhost',
PORT: process.env.APPPORT || 7071,
COMPANY_LINK: {
FB: "http://www.facebook.com/",
TWITTER: "http://www.twitter.com/",
},
JWT: {
KEY: process.env.JWTKEY || 'lib',
SECRET: process.env.JWTSECRET || 'lib',
},
CLOUDINARY: {
NAME: process.env.CLOUDINARY_APINAME,
KEY: process.env.CLOUDINARY_APIKEY,
SECRET: process.env.CLOUDINARY_APISECRET,
URL: process.env.CLOUDINARY_APIURL,
},
GOOGLE: {
ID: process.env.GOOGLEAUTHID,
SECRET: process.env.GOOGLEAUTHSECRET,
CALLBACKURL: process.env.GOOGLEAUTHCALLBACKURL,
USER: process.env.GOOGLEMAILSUER,
PASS: process.env.GOOGLEMAILPASS,
},
FB: {
ID: process.env.FBAUTHID,
SECRET: process.env.FBAUTHSECRET,
CALLBACKURL: process.env.FBAUTHCALLBACKURL,
},
EVENT_STORE_SETTINGS: {
protocol: process.env.EVENTSTOREPROTOCOL || 'amqp',
hostname: process.env.EVENTSTOREHOSTNAME || 'localhost',
tcpPort: process.env.EVENTSTORETCPPORT || 5672,
httpPort: process.env.EVENTSTOREHTTPPORT || 2113,
credentials: {
username: process.env.EVENTSTORECREDENTIALSUSERNAME || 'lib-test',
password: process.env.EVENTSTORECREDENTIALSPASSWORD || '12345678',
},
poolOptions: {
min: process.env.EVENTSTOREPOOLOPTIONSMIN || 1,
max: process.env.EVENTSTOREPOOLOPTIONSMAX || 10,
},
},
DB_SETTINGS: {
host: process.env.DBHOST || 'localhost',
port: process.env.DBPORT || 5434,
username: process.env.DBUSERNAME || 'postgres',
password: process.env.DBPASSWORD || '123',
database: process.env.DBDATABASE || 'onepiece',
schema: process.env.DBSCHEMA || 'public',
userTable: process.env.DBUSERTABLE || 'user',
},
REDIS_URL: process.env.REDIS_URL || "redis://127.0.0.1:6382",
GEO_CONFIGS: {
key: process.env.GEOKEY,
secret: process.env.GEOSECRET
}
},
development: {},
production: {
PORT: process.env.APPPORT || 7071,
},
test: {
PORT: 7071,
},
};
const config = { ...configs.base, ...configs[env] };
export { config };