-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
113 lines (96 loc) · 3.49 KB
/
Copy pathutils.js
File metadata and controls
113 lines (96 loc) · 3.49 KB
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
exports.getIP = function () {
var interfaces = require('os').networkInterfaces();
for (var devName in interfaces) {
var iface = interfaces[devName];
for (var i = 0; i < iface.length; i++) {
var alias = iface[i];
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) return alias.address;
}
}
return '0.0.0.0';
};
// Push Notification for parse-server on stalk session server.
exports.getPushConfig = function () {
// https://github.com/yongjhih/docker-parse-server/blob/master/index.js
var gcmId = process.env.GCM_ID;
var gcmKey = process.env.GCM_KEY;
var iosPushConfigs = new Array();
var isFile = function(f) {
var b = false;
try {
b = fs.statSync(f).isFile();
} catch (e) {
}
return b;
}
var productionBundleId = process.env.PRODUCTION_BUNDLE_ID;
var productionPfx = process.env.PRODUCTION_PFX || '/certs/production-pfx.p12';
productionPfx = isFile(productionPfx) ? productionPfx : null;
var productionCert = process.env.PRODUCTION_CERT || '/certs/production-pfx-cert.pem';
productionCert = isFile(productionCert) ? productionCert : null;
var productionKey = process.env.PRODUCTION_KEY || '/certs/production-pfx-key.pem';
productionKey = isFile(productionKey) ? productionKey : null;
var productionPushConfig;
if (productionBundleId && (productionPfx || (productionCert && productionKey))) {
productionPushConfig = {
pfx: productionPfx,
cert: productionCert,
key: productionKey,
bundleId: productionBundleId,
production: true
};
iosPushConfigs.push(productionPushConfig);
}
var devBundleId = process.env.DEV_BUNDLE_ID;
var devPfx = process.env.DEV_PFX || '/certs/dev-pfx.p12';
devPfx = isFile(devPfx) ? devPfx : null;
var devCert = process.env.DEV_CERT || '/certs/dev-pfx-cert.pem';
devCert = isFile(devCert) ? devCert : null;
var devKey = process.env.DEV_KEY || '/certs/dev-pfx-key.pem';
devKey = isFile(devKey) ? devKey : null;
var devPushConfig;
if (devBundleId && (devPfx || (devCert && devKey))) { // exsiting files if not null
devPushConfig = {
pfx: devPfx,
cert: devCert,
key: devKey,
bundleId: devBundleId,
production: false
};
iosPushConfigs.push(devPushConfig);
}
if(process.env.APNS_BUNDLES_ID && process.env.APNS_BUNDLES_P12 && process.env.APNS_BUNDLES_PROD) {
var APNSBundlesId = process.env.APNS_BUNDLES_ID.split(',').map(function(entry) {
return entry.trim();
});
var APNSBundlesP12 = process.env.APNS_BUNDLES_P12.split(',').map(function(entry) {
return entry.trim();
});
var APNSBundlesProd = process.env.APNS_BUNDLES_PROD.split(',').map(function(entry) {
return entry.trim();
});
if(APNSBundlesId.length === APNSBundlesP12.length && APNSBundlesP12.length === APNSBundlesProd.length) {
for (var i = 0; i < APNSBundlesId.length; i++) {
APNSpushConfig = {
pfx: APNSBundlesP12[i],
bundleId: APNSBundlesId[i],
production: (APNSBundlesProd[i] === 'true' ? true : false)
};
iosPushConfigs.push(APNSpushConfig);
}
}
}
var pushConfig = {};
if (gcmId && gcmKey) {
pushConfig.android = {
senderId: gcmId,
apiKey: gcmKey
}
}
if (iosPushConfigs.length > 0) {
pushConfig.ios = iosPushConfigs;
//console.log('Multiple iOS push configurations.')
}
console.log(pushConfig);
return pushConfig;
}