diff --git a/README.md b/README.md index 85fa56c41d..8a15e2e4ad 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Read the full server guide here: https://parse.com/docs/server/guide ### For Local Development -* Make sure you have at least Node 4.1. `node --version` +* Make sure you have at least Node 8.0. `node --version` * Clone this repo and change directory to it. * `npm install` * Install mongo locally using http://docs.mongodb.org/master/tutorial/install-mongodb-on-os-x/ diff --git a/app.json b/app.json index a4b9a67dc3..022859b272 100644 --- a/app.json +++ b/app.json @@ -16,6 +16,10 @@ "MASTER_KEY": { "description": "A key that overrides all permissions. Keep this secret.", "value": "myMasterKey" + }, + "SERVER_URL": { + "description": "URL to connect to your Heroku instance (update with your app's name + PARSE_MOUNT)", + "value": "http://yourappname.herokuapp.com/parse" } }, "image": "heroku/nodejs", diff --git a/cloud/main.js b/cloud/main.js index 8925fe4cc5..4d2afb8266 100644 --- a/cloud/main.js +++ b/cloud/main.js @@ -1,4 +1,72 @@ +// Android push test +// To be used with: +// https://github.com/codepath/ParsePushNotificationExample +// See https://github.com/codepath/ParsePushNotificationExample/blob/master/app/src/main/java/com/test/MyCustomReceiver.java -Parse.Cloud.define('hello', function(req, res) { - res.success('Hi'); +Parse.Cloud.define('pushChannelTest', function(request, response) { + + // request has 2 parameters: params passed by the client and the authorized user + var params = request.params; + var user = request.user; + + var customData = params.customData; + var launch = params.launch; + var broadcast = params.broadcast; + + // use to custom tweak whatever payload you wish to send + var pushQuery = new Parse.Query(Parse.Installation); + pushQuery.equalTo("deviceType", "android"); + + var payload = {}; + + if (customData) { + payload.customdata = customData; + } + else if (launch) { + payload.launch = launch; + } + else if (broadcast) { + payload.broadcast = broadcast; + } + + // Note that useMasterKey is necessary for Push notifications to succeed. + + Parse.Push.send({ + where: pushQuery, // for sending to a specific channel + data: payload, + }, { success: function() { + console.log("#### PUSH OK"); + }, error: function(error) { + console.log("#### PUSH ERROR" + error.message); + }, useMasterKey: true}); + + response.success('success'); }); + +// iOS push testing +Parse.Cloud.define("iosPushTest", function(request, response) { + + // request has 2 parameters: params passed by the client and the authorized user + var params = request.params; + var user = request.user; + + // Our "Message" class has a "text" key with the body of the message itself + var messageText = params.text; + + var pushQuery = new Parse.Query(Parse.Installation); + pushQuery.equalTo('deviceType', 'ios'); // targeting iOS devices only + + Parse.Push.send({ + where: pushQuery, // Set our Installation query + data: { + alert: "Message: " + messageText + } + }, { success: function() { + console.log("#### PUSH OK"); + }, error: function(error) { + console.log("#### PUSH ERROR" + error.message); + }, useMasterKey: true}); + + response.success('success'); +}); + diff --git a/index.js b/index.js index a196c911b4..06a741201f 100644 --- a/index.js +++ b/index.js @@ -3,18 +3,52 @@ var express = require('express'); var ParseServer = require('parse-server').ParseServer; +var path = require('path'); -var databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_URI +var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI; if (!databaseUri) { console.log('DATABASE_URI not specified, falling back to localhost.'); } +var pushConfig = {}; + +if (process.env.FCM_API_KEY) { + pushConfig['android'] = { apiKey: process.env.FCM_API_KEY || ''}; +} + +if (process.env.APNS_ENABLE) { + pushConfig['ios'] = [ + { + pfx: 'ParsePushDevelopmentCertificate.p12', // P12 file only + bundleId: 'beta.codepath.parsetesting', // change to match bundleId + production: false // dev certificate + } + ] +} + + +var filesAdapter = null; // enable Gridstore to be the default +if (process.env.S3_ENABLE) { + var S3Adapter = require('parse-server').S3Adapter; + + filesAdapter = new S3Adapter( + process.env.AWS_ACCESS_KEY, + process.env.AWS_SECRET_ACCESS_KEY, + {bucket: process.env.AWS_BUCKET_NAME, bucketPrefix: "", directAccess: true} + ); +} + var api = new ParseServer({ databaseURI: databaseUri || 'mongodb://localhost:27017/dev', cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js', appId: process.env.APP_ID || 'myAppId', - masterKey: process.env.MASTER_KEY || '' //Add your master key here. Keep it secret! + masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret! + push: pushConfig, + filesAdapter: filesAdapter, + liveQuery: { classNames: ["Message"]}, + publicServerURL: process.env.SERVER_URL || 'http://localhost/parse', + serverURL: process.env.SERVER_URL || 'http://localhost/parse' // needed for Parse Cloud and push notifications }); // Client-keys like the javascript key or the .NET key are not necessary with parse-server // If you wish you require them, you can set them as options in the initialization above: @@ -22,16 +56,23 @@ var api = new ParseServer({ 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 dream of being a web site.'); + res.status(200).send('I dream of being a website. Please star the parse-server repo on GitHub!'); }); var port = process.env.PORT || 1337; -app.listen(port, function() { +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); diff --git a/package.json b/package.json index 949e634418..881019d7c5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "parse-server-example", - "version": "1.0.0", + "version": "1.4.0", "description": "An example Parse API server using the parse-server module", "main": "index.js", "repository": { @@ -9,15 +9,15 @@ }, "license": "MIT", "dependencies": { - "express": "~4.2.x", + "express": "~4.11.x", "kerberos": "~0.0.x", - "parse": "~1.6.12", - "parse-server": "~2.0" + "parse": "~2.11.0", + "parse-server": "*" }, "scripts": { "start": "node index.js" }, "engines": { - "node": ">=4.1" + "node": ">=8" } }