forked from parse-community/parse-server-example
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
141 lines (129 loc) · 4.73 KB
/
index.js
File metadata and controls
141 lines (129 loc) · 4.73 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');
//Using Config File for localhost environment variables
if (!process.env.SERVER_URL) {
process.env = require('./config');
}
// Declares Database URI
var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}
var apiConfig = {
databaseURI: databaseUri,
serverURL: process.env.SERVER_URL,
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID,
appName: process.env.APP_NAME,
masterKey: process.env.MASTER_KEY,
javascriptKey: process.env.JS_KEY,
restAPIKEY: process.env.RESTAPI_KEY,
clientKey: process.env.CLIENT_KEY,
publicServerURL: process.env.SERVER_URL,
liveQuery: {
classNames: [] // List of classes to support for query subscriptions
}
};
if (process.env.FILE_KEY){
//Using S3Adapter for File Storage
var S3Adapter = require('parse-server').S3Adapter;
apiConfig.fileKey = process.env.FILE_KEY;
apiConfig.filesAdapter = new S3Adapter(
process.env.AWS_ACCESS_KEY_ID,
process.env.AWS_SECRET_ACCESS_KEY,
process.env.BUCKET_NAME,
{directAccess: true, bucketPrefix: process.env.BUCKET_PREFIX}
);
}
if (process.env.VERIFY_EMAILS){
//Sets Email Verification for user account authentication
apiConfig.verifyUserEmails = ((process.env.VERIFY_EMAILS == "true") ? true : false);
}
if (process.env.MAIL_EMAIL) {
//Uses a nodemailer custom adapter for mail sending
var nodeMailerAdapter = require('./nodeMailerAdapter');
apiConfig.emailAdapter = nodeMailerAdapter({
password:process.env.MAIL_PASSWORD || 'myPassword',
fromAddress:process.env.MAIL_FROMADDRESS || 'My company <test@domain>'
});
}
if (process.env.INVALID_LINK_URL) {
//Uses custom parse links for email verification pages
apiConfig.customPages = {
invalidLink: process.env.INVALID_LINK_URL,
verifyEmailSuccess: process.env.VERIFY_EMAIL_URL,
choosePassword: process.env.CHOOSE_PASSWORD_URL,
passwordResetSuccess: process.env.PASSWORD_RESET_SUCCESS_URL
};
}
var pushConfig = {}; //Using Parse Push Default Adapter (optional)
if (process.env.PUSH_GCM_ID){
//Using Android Pushes
pushConfig.android = {
senderId: process.env.PUSH_GCM_ID,
apiKey: process.env.PUSH_GCM_API_KEY
};
}
if (process.env.PROD_PUSH_CERT_PATH || process.env.DEV_PUSH_CERT_HEX){
//Using iOS Pushes
pushConfig.ios = [
{
pfx: process.env.DEV_PUSH_CERT_PATH || new Buffer(process.env.DEV_PUSH_CERT_HEX, 'hex'), // Dev PFX or P12
bundleId: process.env.DEV_PUSH_CERT_BUNDLE,
production: false // Dev
},
{
pfx: process.env.PROD_PUSH_CERT_PATH || new Buffer(process.env.PROD_PUSH_CERT_HEX, 'hex'), // Prod PFX or P12
bundleId: process.env.PROD_PUSH_CERT_BUNDLE,
production: true // Prod
}
];
}
if (process.env.SNS_ACCESS_KEY){
//Using Amazon SNS Push Service Adapter
pushConfig = {
pushTypes : {
android: {
ARN: process.env.SNS_PUSH_ANDROID_ARN
},
ios: {
ARN: process.env.SNS_PUSH_IOS_ARN,
production: ((process.env.SNS_PROD_ENV == "true") ? true : false),
bundleId: process.env.SNS_PUSH_CERT_BUNDLE
}
},
accessKey: process.env.SNS_ACCESS_KEY,
secretKey: process.env.SNS_SECRET_ACCESS_KEY,
region: process.env.SNS_PUSH_REGION
};
var SNSPushAdapter = require('parse-server-sns-adapter');
var snsPushAdapter = new SNSPushAdapter(pushConfig);
pushConfig['adapter'] = snsPushAdapter;
}
if (process.env.SNS_ACCESS_KEY || process.env.PUSH_GCM_ID || process.env.PROD_PUSH_CERT_PATH || process.env.PROD_PUSH_CERT_HEX){
//If any push configuration used, add to the Api Configuration
apiConfig.push = pushConfig;
}
//Custom Parse Server Options
var api = new ParseServer(apiConfig);
// Starts Parse Server App using express
var app = express();
// Serve static assets from the /public folder
app.use('/public', express.static(path.join(__dirname, '/public')));
// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);
// Parse Server plays nicely with the rest of your web routes
app.get('/', function(req, res) {
res.status(200).send('I am Parse Server, running fine!');
});
//Starts Parse Server on Port 4000 or one set by Heroku Variables
var port = process.env.PORT || 4000;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
console.log('parse-server-example running on port ' + port + '.');
});
// This will enable the Live Query real-time server
ParseServer.createLiveQueryServer(httpServer);