You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _includes/cloudcode/cloud-code-advanced.md
+25-2Lines changed: 25 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ A simple GET request would look like:
8
8
9
9
```javascript
10
10
Parse.Cloud.httpRequest({
11
-
url:'http://www.awesomewebsite.com/'
11
+
url:'https://www.awesomewebsite.com/'
12
12
}).then(function(httpResponse) {
13
13
// success
14
14
console.log(httpResponse.text);
@@ -24,7 +24,7 @@ A GET request that specifies the port number would look like:
24
24
25
25
```javascript
26
26
Parse.Cloud.httpRequest({
27
-
url:'http://www.awesomewebsite.com:8080/'
27
+
url:'https://www.awesomewebsite.com:8080/'
28
28
}).then(function(httpResponse) {
29
29
console.log(httpResponse.text);
30
30
}, function(httpResponse) {
@@ -34,6 +34,19 @@ Parse.Cloud.httpRequest({
34
34
35
35
Valid port numbers are 80, 443, and all numbers from 1025 through 65535.
36
36
37
+
By default, `Parse.Cloud.httpRequest` does not follow redirects caused by HTTP 3xx response codes, the `followRedirects: true` option can be used to change this.
38
+
39
+
```javascript
40
+
Parse.Cloud.httpRequest({
41
+
url:'https://www.awesomewebsite.com/',
42
+
followRedirects:true
43
+
}).then(function(httpResponse) {
44
+
console.log(httpResponse.text);
45
+
}, function(httpResponse) {
46
+
console.error('Request failed with response code '+httpResponse.status);
47
+
});
48
+
```
49
+
37
50
### Query Parameters
38
51
39
52
You can specify query parameters to append to the end of the url by setting `params` on the options object. You can either pass a JSON object of key value pairs like:
@@ -569,3 +582,13 @@ Here's an example of the JSON data that would be sent in the request to this web
569
582
```
570
583
571
584
After setting up your webhook in the Dashboard UI, you'll be acurately decrementing comment counts!
585
+
586
+
# Config
587
+
Parse Config offers a convenient way to configure parameters in Cloud Code.
By default, Parse Config parameters can be publicly read which may be undesired if the parameter contains sensitive information that should not be exposed to clients. A parameter can be made readable only with the master key by setting the `Requires master key?` property via the Parse Dashboard to `Yes`.
Copy file name to clipboardExpand all lines: _includes/cloudcode/cloud-code.md
+38-10Lines changed: 38 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -192,16 +192,6 @@ If the function throws, the `Review` object will not be saved, and the client wi
192
192
193
193
One useful tip is that even if your mobile app has many different versions, the same version of Cloud Code applies to all of them. Thus, if you launch an application that doesn't correctly check the validity of input data, you can still fix this problem by adding a validation with `beforeSave`.
194
194
195
-
If you want to use `beforeSave` for a predefined class in the Parse JavaScript SDK (e.g. [Parse.User]({{ site.apis.js }}classes/Parse.User.html)), you should not pass a String for the first argument. Instead, you should pass the class itself:
196
-
197
-
```javascript
198
-
Parse.Cloud.beforeSave(Parse.User, (request) => {
199
-
if (!request.object.get("email")) {
200
-
throw"email is required for signup";
201
-
}
202
-
});
203
-
```
204
-
205
195
## Modifying Objects on Save
206
196
207
197
In some cases, you don't want to throw out invalid data. You just want to tweak it a bit before saving it. `beforeSave` can handle this case, too. Any adjustment you make to request.object will be saved.
*Available only on parse-server cloud code starting 2.6.2*
465
+
466
+
Sometimes you may want to monitor Live Query Events to be used with a 3rd Party such as datadog. The `onLiveQueryEvent` trigger can log events triggered, number of clients connected, number of subscriptions and errors.
467
+
468
+
```javascript
469
+
Parse.Cloud.onLiveQueryEvent(({
470
+
event,
471
+
client,
472
+
sessionToken,
473
+
useMasterKey,
474
+
installationId,
475
+
clients,
476
+
subscriptions,
477
+
error
478
+
}) => {
479
+
if (event!=='ws_disconnect') {
480
+
return;
481
+
}
482
+
// Do your magic
483
+
});
484
+
```
485
+
*client, sessionToken, useMasterKey and installationId are available on parse-server cloud code 3.8.0+*
486
+
487
+
To learn more, read the [Parse LiveQuery Protocol Specification](https://github.com/parse-community/parse-server/wiki/Parse-LiveQuery-Protocol-Specification)
488
+
489
+
## Events
490
+
491
+
* connect
492
+
* subscribe
493
+
* unsubscribe
494
+
* ws_connect
495
+
* ws_disconnect
496
+
* ws_disconnect_error
497
+
498
+
"connect" differs from "ws_connect", the former means that the client completed the connect procedure as defined by Parse Live Query protocol, where "ws_connect" just means that a new websocket was created.
499
+
472
500
# Using the Master Key in cloud code
473
501
Set `useMasterKey:true` in the requests that require master key.
After starting the server, you can visit [http://localhost:1337/playground](http://localhost:1337/playground) in your browser to start playing with your GraphQL API.
@@ -41,7 +41,15 @@ After starting the server, you can visit [http://localhost:1337/playground](http
41
41
42
42
## Using Express.js
43
43
44
-
You can also mount the GraphQL API in an Express.js application together with the REST API or solo:
44
+
You can also mount the GraphQL API in an Express.js application together with the REST API or solo. You first need to create a new project and install the required dependencies:
45
+
46
+
```bash
47
+
$ mkdir my-app
48
+
$ cd my-app
49
+
$ npm install parse-server express --save
50
+
```
51
+
52
+
Then, create an `index.js` file with the following content:
45
53
46
54
```js
47
55
constexpress=require('express');
@@ -53,7 +61,8 @@ const parseServer = new ParseServer({
53
61
databaseURI:'mongodb://localhost:27017/test',
54
62
appId:'APPLICATION_ID',
55
63
masterKey:'MASTER_KEY',
56
-
serverURL:'http://localhost:1337/parse'
64
+
serverURL:'http://localhost:1337/parse',
65
+
publicServerURL:'http://localhost:1337/parse'
57
66
});
58
67
59
68
constparseGraphQLServer=newParseGraphQLServer(
@@ -75,7 +84,14 @@ app.listen(1337, function() {
75
84
});
76
85
```
77
86
78
-
After starting the server, you can visit [http://localhost:1337/playground](http://localhost:1337/playground) in your browser to start playing with your GraphQL API.
87
+
And finally start your app:
88
+
89
+
```bash
90
+
$ npx mongodb-runner start
91
+
$ node index.js
92
+
```
93
+
94
+
After starting the app, you can visit [http://localhost:1337/playground](http://localhost:1337/playground) in your browser to start playing with your GraphQL API.
79
95
80
96
⚠️ Please do not mount the GraphQL Playground in production as anyone could access your API Playground and read or change your application's data. [Parse Dashboard](#running-parse-dashboard) has a built-in GraphQL Playground and it is the recommended option for production apps.
0 commit comments