Skip to content

Commit 650ce3b

Browse files
dblythymtrezza
andauthored
Include coverage for Parse Server Example (#386)
* new: coverage example * update error code * include prettier * add watch * Update README.md * Update ci.yml * Revert "Update ci.yml" This reverts commit fd797ea. * Update main.js * Update main.js * Update package.json * Update README.md * Update README.md * Update README.md * Update README.md restructured README * Update README.md added ToC heading Co-authored-by: Manuel Trezza <[email protected]>
1 parent 2bd4fb7 commit 650ce3b

12 files changed

+201
-121
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ lib-cov
1212

1313
# Coverage directory used by tools like istanbul
1414
coverage
15+
.nyc_output
1516

1617
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
1718
.grunt

.nycrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"reporter": [
3+
"lcov",
4+
"text-summary"
5+
],
6+
"exclude": [
7+
"**/spec/**"
8+
]
9+
}
10+

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
semi: true
2+
trailingComma: "es5"
3+
singleQuote: true
4+
arrowParens: "avoid"
5+
printWidth: 100

README.md

+90-56
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
1-
# parse-server-example
1+
# parse-server-example <!-- omit in toc -->
22

33
[![Join The Conversation](https://img.shields.io/discourse/https/community.parseplatform.org/topics.svg)](https://community.parseplatform.org/c/parse-server)
44
[![Backers on Open Collective](https://opencollective.com/parse-server/tiers/backers/badge.svg)][open-collective-link]
55
[![Sponsors on Open Collective](https://opencollective.com/parse-server/tiers/sponsors/badge.svg)][open-collective-link]
66
[![License][license-svg]][license-link]
77
[![Twitter Follow](https://img.shields.io/twitter/follow/ParsePlatform.svg?label=Follow%20us%20on%20Twitter&style=social)](https://twitter.com/intent/follow?screen_name=ParsePlatform)
88

9-
Example project using the [parse-server](https://github.com/ParsePlatform/parse-server) module on Express.
10-
11-
Read the full Parse Server guide here: https://github.com/ParsePlatform/parse-server/wiki/Parse-Server-Guide
12-
13-
### For Local Development
9+
Example project using the [parse-server](https://github.com/ParsePlatform/parse-server) module on Express. Read the full [Parse Server Guide](https://docs.parseplatform.org/parse-server/guide/) for more information.
10+
11+
# Table of Contents <!-- omit in toc -->
12+
13+
- [Local Development](#local-development)
14+
- [Helpful Scripts](#helpful-scripts)
15+
- [Remote Deployment](#remote-deployment)
16+
- [Heroku](#heroku)
17+
- [AWS Elastic Beanstalk](#aws-elastic-beanstalk)
18+
- [Microsoft Azure App Service](#microsoft-azure-app-service)
19+
- [Google App Engine](#google-app-engine)
20+
- [Scalingo](#scalingo)
21+
- [OpenShift Online (Next Gen)](#openshift-online-next-gen)
22+
- [Using Parse Server](#using-parse-server)
23+
- [Health Check](#health-check)
24+
- [APIs and SDKs](#apis-and-sdks)
25+
- [REST API](#rest-api)
26+
- [JavaScript](#javascript)
27+
- [Android](#android)
28+
- [iOS / tvOS / iPadOS / macOS (Swift)](#ios--tvos--ipados--macos-swift)
29+
30+
# Local Development
1431

1532
* Make sure you have at least Node 4.3. `node --version`
1633
* Clone this repo and change directory to it.
@@ -22,44 +39,49 @@ Read the full Parse Server guide here: https://github.com/ParsePlatform/parse-se
2239
* You now have a database named "dev" that contains your Parse data
2340
* Install ngrok and you can test with devices
2441

25-
### Getting Started With Heroku + mLab Development
42+
## Helpful Scripts
43+
These scripts can help you to develop your app for Parse Server:
44+
45+
* `npm run watch` will start your Parse Server and restart if you make any changes.
46+
* `npm run lint` will check the linting of your cloud code, tests and `index.js`, as defined in `.eslintrc.json`.
47+
* `npm run lint-fix` will attempt fix the linting of your cloud code, tests and `index.js`.
48+
* `npm run prettier` will help improve the formatting and layout of your cloud code, tests and `index.js`, as defined in `.prettierrc`.
49+
* `npm run test` will run any tests that are written in `/spec`.
50+
* `npm run coverage` will run tests and check coverage. Output is available in the `/coverage` folder.
2651

27-
#### With the Heroku Button
52+
# Remote Deployment
53+
54+
## Heroku
2855

2956
[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)
3057

31-
#### Without It
58+
Alternatively, to deploy manually:
3259

3360
* Clone the repo and change directory to it
3461
* Log in with the [Heroku Toolbelt](https://toolbelt.heroku.com/) and create an app: `heroku create`
3562
* Use the [mLab addon](https://elements.heroku.com/addons/mongolab): `heroku addons:create mongolab:sandbox --app YourAppName`
3663
* 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`
3764
* Deploy it with: `git push heroku master`
3865

39-
### Getting Started With AWS Elastic Beanstalk
40-
41-
#### With the Deploy to AWS Button
66+
## AWS Elastic Beanstalk
4267

4368
<a title="Deploy to AWS" href="https://console.aws.amazon.com/elasticbeanstalk/home?region=us-west-2#/newApplication?applicationName=ParseServer&solutionStackName=Node.js&tierName=WebServer&sourceBundleUrl=https://s3.amazonaws.com/elasticbeanstalk-samples-us-east-1/eb-parse-server-sample/parse-server-example.zip" target="_blank"><img src="http://d0.awsstatic.com/product-marketing/Elastic%20Beanstalk/deploy-to-aws.png" height="40"></a>
4469

45-
#### Without It
70+
Alternatively, deploy your local changes manually:
4671

4772
* Clone the repo and change directory to it
4873
* Log in with the [AWS Elastic Beanstalk CLI](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html), select a region, and create an app: `eb init`
4974
* Create an environment and pass in MongoDB URI, App ID, and Master Key: `eb create --envvars DATABASE_URI=<replace with URI>,APP_ID=<replace with Parse app ID>,MASTER_KEY=<replace with Parse master key>`
5075

51-
### Getting Started With Microsoft Azure App Service
52-
53-
#### With the Deploy to Azure Button
76+
## Microsoft Azure App Service
5477

5578
[![Deploy to Azure](http://azuredeploy.net/deploybutton.png)](https://portal.azure.com/#create/Microsoft.ParseServer)
5679

5780
Detailed information is available here:
5881
* [Parse Server with Azure Managed Services](https://azure.microsoft.com/en-us/marketplace/partners/microsoft/parseserver/)
5982
* [Parse Server Azure Blog Post](https://azure.microsoft.com/en-us/blog/announcing-the-publication-of-parse-server-with-azure-managed-services/)
6083

61-
62-
### Getting Started With Google App Engine
84+
## Google App Engine
6385

6486
1. Clone the repo and change directory to it
6587
1. Create a project in the [Google Cloud Platform Console](https://console.cloud.google.com/).
@@ -75,13 +97,11 @@ Detailed information is available here:
7597
A detailed tutorial is available here:
7698
[Running Parse server on Google App Engine](https://cloud.google.com/nodejs/resources/frameworks/parse-server)
7799

78-
### Getting Started With Scalingo
79-
80-
#### With the Scalingo button
100+
## Scalingo
81101

82102
[![Deploy to Scalingo](https://cdn.scalingo.com/deploy/button.svg)](https://my.scalingo.com/deploy)
83103

84-
#### Without it
104+
Alternatively, to deploy manually:
85105

86106
* Clone the repo and change directory to it
87107
* Log in with the [Scalingo CLI](http://cli.scalingo.com/) and create an app: `scalingo create my-parse`
@@ -90,7 +110,7 @@ A detailed tutorial is available here:
90110
* By default it will use a path of /parse for the API routes. To change this, or use older client SDKs, run `scalingo env-set PARSE_MOUNT=/1`
91111
* Deploy it with: `git push scalingo master`
92112

93-
### Getting Started With OpenShift Online (Next Gen)
113+
## OpenShift Online (Next Gen)
94114

95115
1. Register for a free [OpenShift Online (Next Gen) account](http://www.openshift.com/devpreview/register.html)
96116
1. Create a project in the [OpenShift Online Console](https://console.preview.openshift.com/console/).
@@ -106,70 +126,84 @@ A detailed tutorial is available here:
106126
A detailed tutorial is available here:
107127
[Running Parse Server on OpenShift Online (Next Gen)](https://blog.openshift.com/parse-server/)
108128

109-
# Using it
129+
# Using Parse Server
130+
131+
## Health Check
132+
133+
You can use the `/health` endpoint to verify that Parse Server is up and running. For example, for local deployment, enter this URL in your browser:
110134

111-
Before using it, you can access a test page to verify if the basic setup is working fine [http://localhost:1337/test](http://localhost:1337/test).
112-
Then you can use the REST API, the JavaScript SDK, and any of our open-source SDKs:
135+
> [http://localhost:1337/parse/health](http://localhost:1337/parse/health)
113136
114-
Example request to a server running locally:
137+
If you deployed Parse Server remotely, change the URL accordingly.
115138

116-
```curl
139+
## APIs and SDKs
140+
141+
Use the REST API, GraphQL API or any of the Parse SDKs to see Parse Server in action. Parse Server comes with a variety of SDKs to cover most common ecosystems and languages, such as JavaScript, Swift, ObjectiveC and Android just to name a few.
142+
143+
The following shows example requests when interacting with a local deployment of Parse Server. If you deployed Parse Server remotely, change the URL accordingly.
144+
145+
### REST API
146+
147+
Save object:
148+
```sh
117149
curl -X POST \
118-
-H "X-Parse-Application-Id: myAppId" \
150+
-H "X-Parse-Application-Id: YOUR_APP_ID" \
119151
-H "Content-Type: application/json" \
120-
-d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' \
152+
-d '{"score":1337}' \
121153
http://localhost:1337/parse/classes/GameScore
122-
154+
```
155+
156+
Call Cloud Code function:
157+
```sh
123158
curl -X POST \
124-
-H "X-Parse-Application-Id: myAppId" \
159+
-H "X-Parse-Application-Id: YOUR_APP_ID" \
125160
-H "Content-Type: application/json" \
126-
-d '{}' \
161+
-d "{}" \
127162
http://localhost:1337/parse/functions/hello
128163
```
129164

130-
Example using it via JavaScript:
165+
### JavaScript
131166

132-
```javascript
133-
Parse.initialize('myAppId','unused');
134-
Parse.serverURL = 'https://whatever.herokuapp.com';
167+
```js
168+
// Initialize SDK
169+
Parse.initialize("YOUR_APP_ID", "unused");
170+
Parse.serverURL = 'http://localhost:1337/parse';
135171

172+
// Save object
136173
const obj = new Parse.Object('GameScore');
137174
obj.set('score',1337);
138175
await obj.save();
139-
console.log(obj.toJSON());
140176

177+
// Query object
141178
const query = new Parse.Query('GameScore');
142179
const objAgain = await query.get(obj.id);
143-
console.log(objAgain.toJSON());
144180
```
145181

146-
Example using it on Android:
182+
### Android
147183
```java
148-
//in your application class
149-
184+
// Initialize SDK in the application class
150185
Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
151-
.applicationId("myAppId")
152-
.server("http://myServerUrl/parse/") // '/' important after 'parse'
186+
.applicationId("YOUR_APP_ID")
187+
.server("http://localhost:1337/parse/") // '/' important after 'parse'
153188
.build());
154189

155-
ParseObject testObject = new ParseObject("TestObject");
156-
testObject.put("foo", "bar");
157-
testObject.saveInBackground();
190+
// Save object
191+
ParseObject obj = new ParseObject("TestObject");
192+
obj.put("foo", "bar");
193+
obj.saveInBackground();
158194
```
159-
Example using it on iOS (Swift):
160-
```swift
161-
//in your AppDelegate
162195

163-
Parse.initializeWithConfiguration(ParseClientConfiguration(block: { (configuration: ParseMutableClientConfiguration) -> Void in
164-
configuration.server = "https://<# Your Server URL #>/parse/" // '/' important after 'parse'
165-
configuration.applicationId = "<# Your APP_ID #>"
196+
### iOS / tvOS / iPadOS / macOS (Swift)
197+
```swift
198+
// Initialize SDK in AppDelegate
199+
Parse.initializeWithConfiguration(ParseClientConfiguration(block: {
200+
(configuration: ParseMutableClientConfiguration) -> Void in
201+
configuration.server = "http://localhost:1337/parse/" // '/' important after 'parse'
202+
configuration.applicationId = "YOUR_APP_ID"
166203
}))
167204
```
168205
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.
169206

170-
-----
171-
As of April 5, 2017, Parse, LLC has transferred this code to the parse-community organization, and will no longer be contributing to or distributing this code.
172-
173207
[license-svg]: https://img.shields.io/badge/license-BSD-lightgrey.svg
174208
[license-link]: LICENSE
175209
[open-collective-link]: https://opencollective.com/parse-server

cloud/functions.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Parse.Cloud.define('hello', req => {
2+
req.log.info(req);
3+
return 'Hi';
4+
});
5+
6+
Parse.Cloud.define('asyncFunction', async req => {
7+
await new Promise(resolve => setTimeout(resolve, 1000));
8+
req.log.info(req);
9+
return 'Hi async';
10+
});
11+
12+
Parse.Cloud.beforeSave('Test', () => {
13+
throw new Parse.Error(9001, 'Saving test objects is not available.');
14+
});

cloud/main.js

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,2 @@
1-
Parse.Cloud.define('hello', (req) => {
2-
req.log.info(req)
3-
return 'Hi';
4-
});
5-
6-
Parse.Cloud.define('asyncFunction', async (req) => {
7-
await new Promise((resolve) => setTimeout(resolve,1000));
8-
req.log.info(req)
9-
return 'Hi async';
10-
});
11-
12-
Parse.Cloud.beforeSave('Test', () => {
13-
throw new Parse.Error(212,'Saving test objects is not available.')
14-
});
1+
// It is best practise to organize your cloud functions group into their own file. You can then import them in your main.js.
2+
require('./functions.js');

index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ const config = {
1717
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
1818
appId: process.env.APP_ID || 'myAppId',
1919
masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
20-
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
20+
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
2121
liveQuery: {
22-
classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
23-
}
22+
classNames: ['Posts', 'Comments'], // List of classes to support for query subscriptions
23+
},
2424
};
2525
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
2626
// If you wish you require them, you can set them as options in the initialization above:
@@ -39,20 +39,20 @@ if (!test) {
3939
}
4040

4141
// Parse Server plays nicely with the rest of your web routes
42-
app.get('/', function(req, res) {
42+
app.get('/', function (req, res) {
4343
res.status(200).send('I dream of being a website. Please star the parse-server repo on GitHub!');
4444
});
4545

4646
// There will be a test page available on the /test path of your server url
4747
// Remove this before launching your app
48-
app.get('/test', function(req, res) {
48+
app.get('/test', function (req, res) {
4949
res.sendFile(path.join(__dirname, '/public/test.html'));
5050
});
5151

5252
const port = process.env.PORT || 1337;
5353
if (!test) {
5454
const httpServer = require('http').createServer(app);
55-
httpServer.listen(port, function() {
55+
httpServer.listen(port, function () {
5656
console.log('parse-server-example running on port ' + port + '.');
5757
});
5858
// This will enable the Live Query real-time server
@@ -61,5 +61,5 @@ if (!test) {
6161

6262
module.exports = {
6363
app,
64-
config
64+
config,
6565
};

package.json

+18-12
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,28 @@
1616
},
1717
"scripts": {
1818
"start": "node index.js",
19-
"lint": "eslint --cache ./cloud && eslint --cache index.js",
20-
"lint-fix": "eslint --cache --fix ./cloud && eslint --cache --fix index.js",
21-
"test": "jasmine"
19+
"lint": "eslint --cache ./cloud && eslint --cache index.js && eslint --cache ./spec",
20+
"lint-fix": "eslint --cache --fix ./cloud && eslint --cache --fix index.js && eslint --cache --fix./spec",
21+
"test": "jasmine",
22+
"coverage": "nyc jasmine",
23+
"prettier": "prettier --write '{cloud,spec}/{**/*,*}.js' 'index.js'",
24+
"watch": "babel-watch index.js"
2225
},
2326
"engines": {
2427
"node": ">=4.3"
2528
},
2629
"devDependencies": {
27-
"eslint": "^7.17.0",
28-
"eslint-config-standard": "^16.0.2",
29-
"eslint-plugin-import": "^2.22.1",
30-
"eslint-plugin-node": "^11.1.0",
31-
"eslint-plugin-promise": "^4.2.1",
32-
"babel-eslint": "^10.1.0",
33-
"jasmine": "^3.6.3",
34-
"mongodb-runner": "^4.8.0",
35-
"bluebird": "^3.7.2"
30+
"babel-eslint": "10.1.0",
31+
"babel-watch": "7.4.0",
32+
"bluebird": "3.7.2",
33+
"eslint": "7.19.0",
34+
"eslint-config-standard": "16.0.2",
35+
"eslint-plugin-import": "2.22.1",
36+
"eslint-plugin-node": "11.1.0",
37+
"eslint-plugin-promise": "4.2.1",
38+
"jasmine": "3.6.4",
39+
"mongodb-runner": "4.8.1",
40+
"nyc": "15.1.0",
41+
"prettier": "2.2.1"
3642
}
3743
}

0 commit comments

Comments
 (0)