Skip to content

Commit 09d3f95

Browse files
committed
Initial release, parse-server-example
0 parents  commit 09d3f95

File tree

6 files changed

+156
-0
lines changed

6 files changed

+156
-0
lines changed

.gitignore

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Logs
2+
logs
3+
*.log
4+
5+
# Runtime data
6+
pids
7+
*.pid
8+
*.seed
9+
10+
# Directory for instrumented libs generated by jscoverage/JSCover
11+
lib-cov
12+
13+
# Coverage directory used by tools like istanbul
14+
coverage
15+
16+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17+
.grunt
18+
19+
# node-waf configuration
20+
.lock-wscript
21+
22+
# Compiled binary addons (http://nodejs.org/api/addons.html)
23+
build/Release
24+
25+
# Dependency directory
26+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
27+
node_modules
28+
29+
# Emacs
30+
*~

README.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# parse-server-example
2+
3+
Example project using the parse-server module on Express.
4+
5+
### For Local Development
6+
7+
* Make sure you have at least Node 4.1. `node --version`
8+
* Clone this repo and change directory to it.
9+
* `npm install`
10+
* Install mongo locally using http://docs.mongodb.org/master/tutorial/install-mongodb-on-os-x/
11+
* Run `mongo` to connect to your database, just to make sure it's working. Once you see a mongo prompt, exit with Control-D
12+
* Run the server with: `npm start`
13+
* 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.
14+
* You now have a database named "dev" that contains your Parse data
15+
* Install ngrok and you can test with devices
16+
17+
### Getting Started With Heroku + Mongolab Development
18+
19+
* Clone the repo and change directory to it
20+
* Use the Heroku Toolbelt to log in and prepare the app
21+
* Use the MongoLab addon: `heroku addons:create mongolab:sandbox`
22+
* Use `heroku config` and note the URI provided by MongoLab under the var MONGOLAB_URI
23+
* Copy this URI and set it as a new config variable: `heroku config:set DATABASE_URI=mongodb://...`
24+
* 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`
25+
* Deploy it with: `git push heroku master`
26+
27+
### Using it
28+
29+
You can use the REST API, the JavaScript SDK, and any of our open-source SDKs:
30+
31+
Example request to a server running locally:
32+
33+
```
34+
curl -X POST \
35+
-H "X-Parse-Application-Id: myAppId" \
36+
-H "Content-Type: application/json" \
37+
-d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' \
38+
http://localhost:1337/parse/classes/GameScore
39+
```
40+
41+
Example using it via JavaScript:
42+
43+
```
44+
Parse.initialize('myAppId','unused');
45+
Parse.serverURL = 'https://whatever.herokuapp.com';
46+
var obj = new Parse.Object('GameScore');
47+
obj.set('score',1337);
48+
obj.save().then(function(obj) {
49+
console.log(obj.toJSON());
50+
var query = new Parse.Query('GameScore');
51+
query.get(obj.id).then(function(objAgain) {
52+
console.log(objAgain.toJSON());
53+
}, function(err) {console.log(err); });
54+
}, function(err) { console.log(err); });
55+
```
56+
57+
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.

cloud/main.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
Parse.Cloud.define('hello', function(req, res) {
3+
res.success('Hi');
4+
});

index.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Example express application adding the parse-server module to expose Parse
2+
// compatible API routes.
3+
4+
var express = require('express');
5+
var ParseServer = require('parse-server').ParseServer;
6+
var http = require('http');
7+
8+
if (!process.env.DATABASE_URI) {
9+
console.log('DATABASE_URI not specified, falling back to localhost.');
10+
}
11+
12+
var api = new ParseServer({
13+
databaseURI: process.env.DATABASE_URI || 'mongodb://localhost:27017/dev',
14+
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
15+
appId: 'myAppId',
16+
masterKey: 'myMasterKey'
17+
});
18+
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
19+
// If you wish you require them, you can set them as options in the initialization above:
20+
// javascriptKey, restAPIKey, dotNetKey, clientKey
21+
22+
var app = express();
23+
24+
// Serve the Parse API on the /parse URL prefix
25+
var mountPath = process.env.PARSE_MOUNT || '/parse';
26+
app.use(mountPath, api);
27+
28+
// Parse Server plays nicely with the rest of your web routes
29+
app.get('/', function(req, res) {
30+
res.status(200).send('I dream of being a web site.');
31+
});
32+
33+
var port = process.env.PORT || 1337;
34+
var httpServer = http.createServer(app);
35+
httpServer.listen(port, function() {
36+
console.log('parse-server-example running on port ' + port + '.');
37+
});

jsconfig.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES6",
4+
"module": "commonjs"
5+
}
6+
}

package.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "parse-server-example",
3+
"version": "1.0.0",
4+
"description": "An example Parse API server using the parse-server module",
5+
"main": "index.js",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/ParsePlatform/open-api-server"
9+
},
10+
"license": "MIT",
11+
"dependencies": {
12+
"express": "~4.2.x",
13+
"parse": "~1.6.12",
14+
"parse-server": "~2.0.0"
15+
},
16+
"scripts": {
17+
"start": "node index.js"
18+
},
19+
"engines": {
20+
"node": ">=4.1"
21+
}
22+
}

0 commit comments

Comments
 (0)