-
Notifications
You must be signed in to change notification settings - Fork 3
/
global.js
41 lines (36 loc) · 1.26 KB
/
global.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
const config = require('./config')
const fs = require('fs');
const path = require('path')
const admin = require('firebase-admin');
admin.initializeApp({ credential: admin.credential.cert(config.serviceAccount), storageBucket: config.storageBucket });
process.on('uncaughtException', (err) => { console.error('Errory:', err);});
process.on('unhandledRejection', (reason, promise) => { console.error('Error:', promise, 'reason:', reason) });
/** function */
const readFeatures = () => {
const dir = path.join(__dirname, "./api");
const dirs = fs.readdirSync(dir);
const list = {};
try {
for (const res of dirs) {
const groups = res.toLowerCase();
list[groups] = [];
const files = fs.readdirSync(`${dir}/${res}`).filter(file => file.endsWith(".js"));
for (const file of files) {
const fitur = require(`${dir}/${res}/${file}`);
list[groups].push(fitur);
}
}
API.list = list;
} catch (e) {
console.error(e);
}
};
/** global */
global.__path = process.cwd()
global.config = require('./config')
global.totalLimit = 25
global.admin = admin
global.bucket = admin.storage().bucket();
global.db = admin.firestore()
global.API = {}
readFeatures()