diff --git a/.jshintignore b/.jshintignore index a78f0306a8..30d96ff17b 100644 --- a/.jshintignore +++ b/.jshintignore @@ -1,5 +1,6 @@ appengine/bower/public/bower_components/** appengine/kraken/public/components/** +appengine/parse-server/cloud/main.js appengine/sails/config/** appengine/sails/tasks/** appengine/sails/assets/** diff --git a/README.md b/README.md index 974c49ffe2..eee8e07bf8 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ __Frameworks__ - Loopback.js - [Source code][loopback_1] | [App Engine Tutorial][loopback_2] | [Live demo][loopback_3] | [Documentation][loopback_4] - Koa.js - [Source code][koa_1] | [App Engine Tutorial][koa_2] | [Live demo][koa_3] | [Documentation][koa_4] - Kraken.js - [Source code][kraken_1] | [App Engine Tutorial][kraken_2] | [Live demo][kraken_3] | [Documentation][kraken_4] +- Parse-server - [Source code][parse_1] - Restify.js - [Source code][restify_1] | [App Engine Tutorial][restify_2] | [Live demo][restify_3] | [Documentation][restify_4] - Sails.js - [Source code][sails_1] | [App Engine Tutorial][sails_2] | [Live demo][sails_3] | [Documentation][sails_4] @@ -190,6 +191,8 @@ See [LICENSE](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/ma [kraken_3]: http://kraken-dot-nodejs-docs-samples.appspot.com [kraken_4]: http://krakenjs.com/ +[parse_1]: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/appengine/parse-server + [restify_1]: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/appengine/restify [restify_2]: https://cloud.google.com/nodejs/resources/frameworks/restify [restify_3]: http://restify-dot-nodejs-docs-samples.appspot.com diff --git a/appengine/parse-server/README.md b/appengine/parse-server/README.md new file mode 100644 index 0000000000..607f918070 --- /dev/null +++ b/appengine/parse-server/README.md @@ -0,0 +1,29 @@ +# Parse-server sample for Google App Engine + +This sample demonstrates deploying a [Parse-server](https://github.com/ParsePlatform/parse-server) +app to [Google App Engine Managed VMs](https://cloud.google.com/appengine). + +## Setup + +1. Create a project in the [Google Cloud Platform Console](https://console.cloud.google.com/). +1. [Enable billing](https://console.cloud.google.com/project/_/settings) for your project. +1. Install the [Google Cloud SDK](https://cloud.google.com/sdk/). +1. Setup a MongoDB server. Here are two possible options: + 1. Create a Google Compute Engine virtual machine with [MongoDB pre-installed](https://cloud.google.com/launcher/?q=mongodb). + 1. Use [MongoLab](https://mongolab.com/google/) to create a free MongoDB deployment on Google Cloud Platform. + +## Running locally + +1. `git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git` +1. `cd appengine/parse-server` +1. `npm install` +1. Set the necessary [environment variables](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/appengine/parse-server/server.js#L23). +1. `npm start` + +## Deploy + +1. Modify `app.yaml` as needed. +1. `gcloud preview app deploy` + +Refer to the [appengine/README.md](../README.md) file for more instructions on +running and deploying. diff --git a/appengine/parse-server/app.yaml b/appengine/parse-server/app.yaml new file mode 100644 index 0000000000..c1c94c6ed4 --- /dev/null +++ b/appengine/parse-server/app.yaml @@ -0,0 +1,37 @@ +# Copyright 2016, Google, Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START app_yaml] +runtime: nodejs +vm: true + +env_variables: + # Your MongoDB URI, e.g. mongodb://user:password@123.456.78.901:27017/db + DATABASE_URI: mongodb://localhost:27017/dev + # Absolute path to your cloud code main.js file + # CLOUD_PATH: + # App id + # REQUIRED + APP_ID: + # master key + # REQUIRED + MASTER_KEY: + # file key + FILE_KEY: + # Mount path for Parse API + PARSE_MOUNT_PATH: /parse + +skip_files: + # Don't deploy node_modules folder + - ^(.*/)?.*/node_modules/.*$ +# [END app_yaml] diff --git a/appengine/parse-server/cloud/main.js b/appengine/parse-server/cloud/main.js new file mode 100644 index 0000000000..dac69b161c --- /dev/null +++ b/appengine/parse-server/cloud/main.js @@ -0,0 +1,17 @@ +// Copyright 2016, Google, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +Parse.Cloud.define('hello', function(req, res) { + res.success('Hello, world!'); +}); diff --git a/appengine/parse-server/package.json b/appengine/parse-server/package.json new file mode 100644 index 0000000000..fed97e7773 --- /dev/null +++ b/appengine/parse-server/package.json @@ -0,0 +1,20 @@ +{ + "name": "appengine-parse-server", + "description": "Parse-server sample for Google App Engine", + "version": "0.0.1", + "private": true, + "license": "Apache Version 2.0", + "author": "Google Inc.", + "engines": { + "node": "~4.2" + }, + "scripts": { + "start": "node server.js", + "monitor": "nodemon server.js", + "deploy": "gcloud preview app deploy" + }, + "dependencies": { + "express": "^4.13.4", + "parse-server": "^2.0.0" + } +} diff --git a/appengine/parse-server/server.js b/appengine/parse-server/server.js new file mode 100644 index 0000000000..980dd62d58 --- /dev/null +++ b/appengine/parse-server/server.js @@ -0,0 +1,44 @@ +// Copyright 2016, Google, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +// [START app] +var express = require('express'); +var ParseServer = require('parse-server').ParseServer; + +var app = express(); + +var parseServer = new ParseServer({ + databaseURI: process.env.DATABASE_URI || 'mongodb://localhost:27017/dev', + cloud: process.env.CLOUD_PATH || __dirname + '/cloud/main.js', + appId: process.env.APP_ID, + masterKey: process.env.MASTER_KEY, + fileKey: process.env.FILE_KEY +}); + +// Mount the Parse API server middleware to /parse +app.use(process.env.PARSE_MOUNT_PATH || '/parse', parseServer); + +app.get('/', function(req, res) { + res.status(200).send('Hello, world!'); +}); + +var server = app.listen(process.env.PORT || 8080, '0.0.0.0', function() { + console.log('App listening at http://%s:%s', server.address().address, + server.address().port); + console.log('Press Ctrl+C to quit.'); +}); + +// [END app] diff --git a/test/appengine/all.test.js b/test/appengine/all.test.js index b8fc037c9c..e4fdf686ee 100644 --- a/test/appengine/all.test.js +++ b/test/appengine/all.test.js @@ -138,6 +138,16 @@ var sampleTests = [ msg: 'Value:', test: /Value: \d\.\d+/ }, + { + dir: 'parse-server', + cmd: 'node', + args: ['server.js'], + msg: 'Hello, world!', + env: { + APP_ID: 'foo', + MASTER_KEY: 'bar' + } + }, { dir: 'pubsub', cmd: 'node',