Skip to content

Commit 120e98f

Browse files
authored
feat: Upgrade to Parse Server 8 using ES6 syntax and Parse JS SDK in example web page (#562)
BREAKING CHANGE: This release upgrades to Parse Server 8. See the Parse Server 8 [change log](https://github.com/parse-community/parse-server/releases/tag/8.0.0) for more details about breaking changes. This release also changes to using ES6 syntax.
1 parent d3fce49 commit 120e98f

14 files changed

+1551
-833
lines changed

.github/workflows/ci.yml

+32-21
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,39 @@ on:
88
- '**'
99
workflow_dispatch:
1010
jobs:
11-
test:
11+
lint:
1212
runs-on: ubuntu-latest
13-
strategy:
14-
matrix:
15-
node-version: [18, 20, 22]
16-
fail-fast: false
17-
name: Test Node ${{ matrix.node-version }}
13+
name: Lint
1814
steps:
19-
- name: Fix usage of insecure GitHub protocol
20-
run: sudo git config --system url."https://github".insteadOf "git://github"
21-
- uses: actions/checkout@v3
22-
- name: Use Node.js ${{ matrix.node-version }}
23-
uses: actions/setup-node@v3
24-
with:
25-
node-version: ${{ matrix.node-version }}
26-
cache: 'npm'
27-
- name: Install Dependancies
28-
run: npm install
29-
- name: Check Linting
30-
run: npm run lint
31-
- name: Run Tests
32-
run: npm run test
15+
- name: Fix usage of insecure GitHub protocol
16+
run: sudo git config --system url."https://github".insteadOf "git://github"
17+
- uses: actions/checkout@v3
18+
- name: Use Node.js 22
19+
uses: actions/setup-node@v3
20+
with:
21+
node-version: 22
22+
cache: 'npm'
23+
- name: Install Dependencies
24+
run: npm ci
25+
- name: Check Linting
26+
run: npm run lint
27+
28+
tests:
29+
runs-on: ubuntu-latest
30+
name: Tests
31+
steps:
32+
- name: Fix usage of insecure GitHub protocol
33+
run: sudo git config --system url."https://github".insteadOf "git://github"
34+
- uses: actions/checkout@v3
35+
- name: Use Node.js 22
36+
uses: actions/setup-node@v3
37+
with:
38+
node-version: 22
39+
cache: 'npm'
40+
- name: Install Dependencies
41+
run: npm ci
42+
- name: Run Tests
43+
run: npm test
3344
concurrency:
3445
group: ${{ github.workflow }}-${{ github.ref }}
35-
cancel-in-progress: true
46+
cancel-in-progress: true

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,14 @@ These scripts can help you to develop your app for Parse Server:
5757
* `npm run lint` will check the linting of your cloud code, tests and `index.js`, as defined in `.eslintrc.json`.
5858
* `npm run lint-fix` will attempt fix the linting of your cloud code, tests and `index.js`.
5959
* `npm run prettier` will help improve the formatting and layout of your cloud code, tests and `index.js`, as defined in `.prettierrc`.
60-
* `npm run test` will run any tests that are written in `/spec`.
60+
* `npm test` will run all tests
6161
* `npm run coverage` will run tests and check coverage. Output is available in the `/coverage` folder.
6262

63+
## Configuration
64+
65+
Configuration is located in `config.js`.
66+
67+
6368
# Remote Deployment
6469

6570
## Heroku

cloud/functions.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ Parse.Cloud.define('hello', req => {
33
return 'Hi';
44
});
55

6-
Parse.Cloud.define('asyncFunction', async req => {
6+
Parse.Cloud.define('helloAsyncFunction', async req => {
77
await new Promise(resolve => setTimeout(resolve, 1000));
88
req.log.info(req);
99
return 'Hi async';
1010
});
1111

12-
Parse.Cloud.beforeSave('Test', () => {
12+
Parse.Cloud.beforeSave('TestObject', () => {
1313
throw new Parse.Error(9001, 'Saving test objects is not available.');
1414
});

cloud/main.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
// It is best practise to organize your cloud functions group into their own file. You can then import them in your main.js.
2-
await import('./functions.js');
2+
await Promise.all([
3+
import('./functions.js')
4+
]);

cloud/schema.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export const schemaDefinitions = [{
2+
className: "TestObject",
3+
fields: {
4+
beforeSave: { type: "Boolean", defaultValue: false },
5+
additionalData: { type: "String" },
6+
},
7+
classLevelPermissions: {
8+
find: { "*": true },
9+
count: { "*": true },
10+
get: { "*": true },
11+
update: { "*": true },
12+
create: { "*": true },
13+
delete: { "*": true },
14+
},
15+
}];

config.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { schemaDefinitions } from "./cloud/schema.js";
2+
export const config = {
3+
databaseURI: process.env.DATABASE_URI || process.env.MONGODB_URI || 'mongodb://localhost:27017/dev',
4+
cloud: process.env.CLOUD_CODE_MAIN || './cloud/main.js',
5+
appId: process.env.APP_ID || 'myAppId',
6+
masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
7+
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
8+
liveQuery: {
9+
classNames: ['Posts', 'Comments'], // List of classes to support for query subscriptions
10+
},
11+
schema: {
12+
definitions: schemaDefinitions,
13+
lockSchemas: true,
14+
strict: true,
15+
recreateModifiedFields: false,
16+
deleteExtraFields: false,
17+
},
18+
};

index.js

+15-35
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,19 @@
44
import express from 'express';
55
import { ParseServer } from 'parse-server';
66
import path from 'path';
7-
const __dirname = path.resolve();
87
import http from 'http';
9-
10-
export const config = {
11-
databaseURI:
12-
process.env.DATABASE_URI || process.env.MONGODB_URI || 'mongodb://localhost:27017/dev',
13-
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
14-
appId: process.env.APP_ID || 'myAppId',
15-
masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
16-
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
17-
liveQuery: {
18-
classNames: ['Posts', 'Comments'], // List of classes to support for query subscriptions
19-
},
20-
};
21-
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
22-
// If you wish you require them, you can set them as options in the initialization above:
23-
// javascriptKey, restAPIKey, dotNetKey, clientKey
24-
25-
export const app = express();
26-
27-
app.set('trust proxy', true);
8+
import { config } from './config.js';
9+
const __dirname = path.resolve();
10+
const app = express();
2811

2912
// Serve static assets from the /public folder
3013
app.use('/public', express.static(path.join(__dirname, '/public')));
3114

3215
// Serve the Parse API on the /parse URL prefix
33-
if (!process.env.TESTING) {
34-
const mountPath = process.env.PARSE_MOUNT || '/parse';
35-
const server = new ParseServer(config);
36-
await server.start();
37-
app.use(mountPath, server.app);
38-
}
16+
const mountPath = process.env.PARSE_MOUNT || '/parse';
17+
const server = new ParseServer(config);
18+
await server.start();
19+
app.use(mountPath, server.app);
3920

4021
// Parse Server plays nicely with the rest of your web routes
4122
app.get('/', function (req, res) {
@@ -48,12 +29,11 @@ app.get('/test', function (req, res) {
4829
res.sendFile(path.join(__dirname, '/public/test.html'));
4930
});
5031

51-
if (!process.env.TESTING) {
52-
const port = process.env.PORT || 1337;
53-
const httpServer = http.createServer(app);
54-
httpServer.listen(port, function () {
55-
console.log('parse-server-example running on port ' + port + '.');
56-
});
57-
// This will enable the Live Query real-time server
58-
await ParseServer.createLiveQueryServer(httpServer);
59-
}
32+
const port = process.env.PORT || 1337;
33+
const httpServer = http.createServer(app);
34+
httpServer.listen(port, function () {
35+
console.log('parse-server-example running on port ' + port + '.');
36+
});
37+
// This will enable the Live Query real-time server
38+
await ParseServer.createLiveQueryServer(httpServer);
39+
console.log(`Visit http://localhost:${port}/test to check the Parse Server`);

0 commit comments

Comments
 (0)