-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
100 lines (81 loc) · 2.82 KB
/
index.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
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
/* This file is part of pgAPI.
pgAPI - Database as a service
Copyright (C) 2018 Praveen Muralidhar
pgAPI is a free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
pgAPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const path = require('path');
const utils = require('./admin/Utils');
const colors = require('colors');
const install = require('./admin/install');
const routeHandler = require('./admin/controllers/Route');
const routes = () => {
}
const adminRouter = () => {
const adminRouter = require('./admin/router');
return adminRouter;
}
const apiRouter = (router) => {
global.pool = {};
global.router = router;
const s = routeHandler.getRoutes();
}
const initialize = async (input) => {
try {
if (!!input && !!input.DB_HOST
&& !!input.DB_USER
&& !!input.DB_PASSWORD
&& !!input.DB_NAME
&& !!input.DB_PORT
&& !!input.PGAPI_SECRET_KEY
) {
utils.loadRuntimeEnvVariables({
DB_HOST : input.DB_HOST,
DB_USER: input.DB_USER,
DB_PASSWORD: input.DB_PASSWORD,
DB_NAME: input.DB_NAME,
DB_PORT: input.DB_PORT,
PGAPI_SECRET_KEY: input.PGAPI_SECRET_KEY,
DEMO_INSTALL: input.DEMO_INSTALL,
SMS_PROVIDER: input.SMS_PROVIDER
});
// let ssl = false;
// if (!!input.DB_SSL && input.DB_SSL === 'Y') {
// ssl = true;
// }
let response = await utils.validateConnection({
host : input.DB_HOST,
port : input.DB_PORT,
database : input.DB_NAME,
username : input.DB_USER,
password : input.DB_PASSWORD,
});
if (response.status === "E") {
throw("pgAPI - failed to initialize - invalid database connection information");
}
await install.loadDB(true);
} else {
throw("pgAPI - failed to initialize - invalid input parameters");
}
} catch(e) {
throw(e)
}
}
const clientSourcePath = () => {
return path.join(path.resolve(__dirname, './dist'));
}
module.exports = {
routes,
adminRouter,
initialize,
clientSourcePath,
apiRouter
}