Browse Source

Initial release, parse-server-example

Fosco Marotto 9 years ago
commit
09d3f95d15
6 changed files with 156 additions and 0 deletions
  1. 30 0
      .gitignore
  2. 57 0
      README.md
  3. 4 0
      cloud/main.js
  4. 37 0
      index.js
  5. 6 0
      jsconfig.json
  6. 22 0
      package.json

+ 30 - 0
.gitignore

@@ -0,0 +1,30 @@
+# Logs
+logs
+*.log
+
+# Runtime data
+pids
+*.pid
+*.seed
+
+# Directory for instrumented libs generated by jscoverage/JSCover
+lib-cov
+
+# Coverage directory used by tools like istanbul
+coverage
+
+# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
+.grunt
+
+# node-waf configuration
+.lock-wscript
+
+# Compiled binary addons (http://nodejs.org/api/addons.html)
+build/Release
+
+# Dependency directory
+# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
+node_modules
+
+# Emacs
+*~

+ 57 - 0
README.md

@@ -0,0 +1,57 @@
+# parse-server-example
+
+Example project using the parse-server module on Express.
+
+### For Local Development
+
+* Make sure you have at least Node 4.1. `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/
+* Run `mongo` to connect to your database, just to make sure it's working. Once you see a mongo prompt, exit with Control-D
+* Run the server with: `npm start`
+* By default it will use a path of /parse for the API routes.  To change this, or use older client SDKs, run `export PARSE_MOUNT=/1` before launching the server.
+* You now have a database named "dev" that contains your Parse data
+* Install ngrok and you can test with devices
+
+### Getting Started With Heroku + Mongolab Development
+
+* Clone the repo and change directory to it
+* Use the Heroku Toolbelt to log in and prepare the app
+* Use the MongoLab addon: `heroku addons:create mongolab:sandbox`
+* Use `heroku config` and note the URI provided by MongoLab under the var MONGOLAB_URI 
+* Copy this URI and set it as a new config variable: `heroku config:set DATABASE_URI=mongodb://...`
+* By default it will use a path of /parse for the API routes.  To change this, or use older client SDKs, run `heroku config:set PARSE_MOUNT=/1`
+* Deploy it with: `git push heroku master`
+
+### Using it
+
+You can use the REST API, the JavaScript SDK, and any of our open-source SDKs:
+
+Example request to a server running locally:
+
+```
+curl -X POST \
+  -H "X-Parse-Application-Id: myAppId" \
+  -H "Content-Type: application/json" \
+  -d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' \
+  http://localhost:1337/parse/classes/GameScore
+```
+
+Example using it via JavaScript:
+
+```
+Parse.initialize('myAppId','unused');
+Parse.serverURL = 'https://whatever.herokuapp.com';
+var obj = new Parse.Object('GameScore');
+obj.set('score',1337);
+obj.save().then(function(obj) {
+  console.log(obj.toJSON());
+  var query = new Parse.Query('GameScore');
+  query.get(obj.id).then(function(objAgain) {
+    console.log(objAgain.toJSON());
+  }, function(err) {console.log(err); });
+}, function(err) { console.log(err); });
+```
+
+You can change the server URL in all of the open-source SDKs, but we're releasing new builds which provide initialization time configuration of this property.

+ 4 - 0
cloud/main.js

@@ -0,0 +1,4 @@
+
+Parse.Cloud.define('hello', function(req, res) {
+  res.success('Hi');
+});

+ 37 - 0
index.js

@@ -0,0 +1,37 @@
+// Example express application adding the parse-server module to expose Parse
+// compatible API routes.
+
+var express = require('express');
+var ParseServer = require('parse-server').ParseServer;
+var http = require('http');
+
+if (!process.env.DATABASE_URI) {
+  console.log('DATABASE_URI not specified, falling back to localhost.');
+}
+
+var api = new ParseServer({
+  databaseURI: process.env.DATABASE_URI || 'mongodb://localhost:27017/dev',
+  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
+  appId: 'myAppId',
+  masterKey: 'myMasterKey'
+});
+// 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:
+// javascriptKey, restAPIKey, dotNetKey, clientKey
+
+var app = express();
+
+// 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.');
+});
+
+var port = process.env.PORT || 1337;
+var httpServer = http.createServer(app);
+httpServer.listen(port, function() {
+  console.log('parse-server-example running on port ' + port + '.');
+});

+ 6 - 0
jsconfig.json

@@ -0,0 +1,6 @@
+{
+    "compilerOptions": {
+        "target": "ES6",
+        "module": "commonjs"
+    }
+}

+ 22 - 0
package.json

@@ -0,0 +1,22 @@
+{
+  "name": "parse-server-example",
+  "version": "1.0.0",
+  "description": "An example Parse API server using the parse-server module",
+  "main": "index.js",
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/ParsePlatform/open-api-server"
+  },
+  "license": "MIT",
+  "dependencies": {
+    "express": "~4.2.x",
+    "parse": "~1.6.12",
+    "parse-server": "~2.0.0"
+  },
+  "scripts": {
+    "start": "node index.js"
+  },
+  "engines": {
+    "node": ">=4.1"
+  }
+}