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: usage/tools/cloudcode.mdx
+19-40Lines changed: 19 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,13 +7,13 @@ As of January 2025, we've started adding optional backend functionality for Powe
7
7
8
8
This makes PowerSync easier to implement for developers who prefer not having to maintain their own backend code and infrastructure (PowerSync's [usual architecture](/installation/app-backend-setup) is to use your own backend to process writes and generate JWTs).
9
9
10
-
We are approaching this in phases, and phase 1 allows using the CloudCode feature of JourneyApps Platform, a [sibling product](https://www.powersync.com/company) of PowerSync. [CloudCode](https://docs.journeyapps.com/reference/cloudcode/cloudcode-overview) is a serverless cloud functions engine based on Node.js and AWS Lambda. It's provided as a fully-managed service running on the same cloud infrastructure as the rest of PowerSync Cloud. PowerSync and JourneyApps Platform share the same login system, so you don’t need to create a separate account to use CloudCode.
10
+
We are approaching this in phases, and phase 1 allows using the CloudCode feature of JourneyApps Platform, a [sibling product](https://www.powersync.com/company) of PowerSync. [CloudCode](https://docs.journeyapps.com/reference/cloudcode/cloudcode-overview) is a serverless cloud functions engine based on Node.js and AWS Lambda. It's provided as a fully-managed service running on the same cloud infrastructure as the rest of PowerSync Cloud. PowerSync and JourneyApps Platform share the same login system, so you don’t need to create a separate account to use CloudCode.
11
11
12
12
<Info>
13
13
We are currently making JourneyApps Platform CloudCode available for free to all our customers who use PowerSync with MongoDB. It does require a bit of "white glove" onboarding from our team. [Contact us](/resources/contact-us) if you want to use this functionality.
14
14
</Info>
15
15
16
-
Phase 2 on our roadmap involves fully integrating CloudCode into the PowerSync Cloud environment.
16
+
Phase 2 on our roadmap involves fully integrating CloudCode into the PowerSync Cloud environment.
17
17
18
18
19
19
# Using CloudCode in JourneyApps Platform for MongoDB Backend Functionality
@@ -169,16 +169,18 @@ You would call the `upload` HTTP API endpoint when you [implement](/installation
169
169
Send an HTTP POST request to `<domain_name>.poweredbyjourney.com/upload`.
170
170
171
171
The body of the request payload should look like this:
1. Open the **CloudCode** section at the top of the IDE.
197
199
2. Select and expand the `upload` task in the panel on the left.
198
-
3. The `index.ts` contains the entry point function that accepts the HTTP request.
199
-
4. The `persister.ts` file connects to the MongoDB database and writes the data to the MongoDB database. You can update this file to introduce your database schema. The default template has an example schema for a To-Do List application:
200
-
201
-
```typescript
202
-
/**
203
-
* Line 13 in upload/persister.ts
204
-
* Sample schema using to-do list demo. Update this based on your DB schema.
205
-
*/
206
-
exportconst schema = {
207
-
lists: {
208
-
_id: types.string,
209
-
created_at: types.date,
210
-
name: types.string,
211
-
owner_id: types.string
212
-
},
213
-
todos: {
214
-
_id: types.string,
215
-
completed: types.boolean,
216
-
created_at: types.date,
217
-
created_by: types.string,
218
-
description: types.string,
219
-
list_id: types.string,
220
-
completed_at: types.date,
221
-
completed_by: types.string
222
-
}
223
-
};
224
-
```
200
+
3. The `index.ts` contains the entry point function that accepts the HTTP request and has a `MongoDBStorage` class which interacts with the MongoDB database to perform inserts, updates and deletes. To adjust how updates are performed take a look at the `updateBatch` function.
225
201
226
202
## Production considerations
227
203
228
-
Before going into production with this solution, you will need to set up authentication on the HTTP endpoints exposed by the CloudCode tasks.
204
+
Before going into production with this solution, you will need to set up authentication on the HTTP endpoints exposed by the CloudCode tasks.
205
+
206
+
If you need more data validations and/or authorization than what is provided by the template, that will need to be customized too.
229
207
230
-
In addition, if you need more data validations and/or authorization than what is provided by the template, that will need to be customized too.
208
+
For production applications you would also want to consider introducing schema validation of the data being written to the source MongoDB database.
209
+
You should use a [purpose-built](https://json-schema.org/tools?query=&sortBy=name&sortOrder=ascending&groupBy=toolingTypes&licenses=&languages=&drafts=&toolingTypes=&environments=&showObsolete=false) library for this, and use MongoDB Schema Validation to enforce the types in the database.
231
210
232
211
Please [contact us](/resources/contact-us) for assistance on either of the above.
0 commit comments