-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
112 lines (98 loc) · 3.49 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
101
102
103
104
105
106
107
108
109
110
111
112
var AzurePushAdapter = require('parse-server-azure-push');
var AzureStorageAdapter = require('parse-server-azure-storage').AzureStorageAdapter;
var DefaultFilesAdapter = require('parse-server/lib/Adapters/Files/FilesAdapter').FilesAdapter;
var DefaultPushAdapter = require('parse-server/lib/Adapters/Push/PushAdapter').PushAdapter;
var util = require('util');
module.exports = (siteRoot, options) => {
options = options || {};
var push = {
HubName: process.env.MS_NotificationHubName || (process.env.WEBSITE_SITE_NAME? process.env.WEBSITE_SITE_NAME + '-hub' : undefined),
ConnectionString: process.env.CUSTOMCONNSTR_MS_NotificationHubConnectionString
};
var storage = {
name: process.env.STORAGE_NAME,
container: process.env.STORAGE_CONTAINER || 'parse',
accessKey: process.env.STORAGE_KEY,
directAccess: true
};
var server = {
appId: process.env.APP_ID || 'appId',
masterKey: process.env.MASTER_KEY || 'masterKey',
databaseURI: process.env.DATABASE_URI || 'mongodb://localhost:27017/dev',
serverURL: (process.env.SERVER_URL || 'http://localhost:1337') + '/parse',
cloud: siteRoot + '/cloud/main.js',
logFolder: siteRoot + '/logs',
filesAdapter: () => {
if (validate('storage', ['name', 'container', 'accessKey']))
return new AzureStorageAdapter(storage.name, storage.container, storage);
else {
return new DefaultFilesAdapter();
}
},
push: {
adapter: () => {
if (validate('push', ['HubName', 'ConnectionString']))
return AzurePushAdapter(push);
else {
return new DefaultPushAdapter();
}
}
},
allowClientClassCreation: false,
enableAnonymousUsers: false
};
var dashboard = {
apps: [
{
appId: server.appId,
serverURL: server.serverURL,
masterKey: server.masterKey,
appName: process.env.WEBSITE_SITE_NAME || 'Parse Server Azure'
}
],
users: [
{
user: server.appId,
pass: server.masterKey
}
]
};
loadConfigFile(options.config || 'config.js');
loadConfigFile(options.local || 'local.js');
var api = {
server: server,
dashboard: dashboard,
push: push,
storage: storage
};
console.log('parse-server-azure-config generated the following configuration:');
console.log(util.inspect(api, { showHidden: false, depth: 4 }))
return api;
function validate(configName, props) {
var valid = props.reduce((configValid, prop) => {
if (!api[configName][prop])
console.log(`Missing required property '${prop}' in ${configName} configuration`);
return configValid && api[configName][prop];
}, true);
if (!valid)
console.log(`Will not setup parse-server-azure-${configName} due to invalid configuration`);
return valid;
}
function loadConfigFile(filename) {
try {
var config = require(`${siteRoot}/${filename}`);
Object.assign(server, config.server);
Object.assign(push, config.push);
Object.assign(storage, config.storage);
// concat apps and users
Object.keys(dashboard).forEach((key) => {
var val = config && config.dashboard && config.dashboard[key];
if (val)
dashboard[key] = dashboard[key].concat(val);
});
} catch (err) {
console.error(err);
console.log(`Couldn't load configuration from ${siteRoot}/${filename}`)
}
}
}