Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Upgrade to Parse Server 8 using ES6 syntax and Parse JS SDK in example web page #562

Merged
merged 18 commits into from
Mar 6, 2025
Merged
53 changes: 32 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,39 @@ on:
- '**'
workflow_dispatch:
jobs:
test:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18, 20, 22]
fail-fast: false
name: Test Node ${{ matrix.node-version }}
name: Lint
steps:
- name: Fix usage of insecure GitHub protocol
run: sudo git config --system url."https://github".insteadOf "git://github"
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install Dependancies
run: npm install
- name: Check Linting
run: npm run lint
- name: Run Tests
run: npm run test
- name: Fix usage of insecure GitHub protocol
run: sudo git config --system url."https://github".insteadOf "git://github"
- uses: actions/checkout@v3
- name: Use Node.js 22
uses: actions/setup-node@v3
with:
node-version: 22
cache: 'npm'
- name: Install Dependencies
run: npm ci
- name: Check Linting
run: npm run lint

tests:
runs-on: ubuntu-latest
name: Tests
steps:
- name: Fix usage of insecure GitHub protocol
run: sudo git config --system url."https://github".insteadOf "git://github"
- uses: actions/checkout@v3
- name: Use Node.js 22
uses: actions/setup-node@v3
with:
node-version: 22
cache: 'npm'
- name: Install Dependencies
run: npm ci
- name: Run Tests
run: npm test
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
cancel-in-progress: true
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ These scripts can help you to develop your app for Parse Server:
* `npm run lint` will check the linting of your cloud code, tests and `index.js`, as defined in `.eslintrc.json`.
* `npm run lint-fix` will attempt fix the linting of your cloud code, tests and `index.js`.
* `npm run prettier` will help improve the formatting and layout of your cloud code, tests and `index.js`, as defined in `.prettierrc`.
* `npm run test` will run any tests that are written in `/spec`.
* `npm test` will run all tests
* `npm run coverage` will run tests and check coverage. Output is available in the `/coverage` folder.

## Configuration

Configuration is located in `config.js`.


# Remote Deployment

## Heroku
Expand Down
4 changes: 2 additions & 2 deletions cloud/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ Parse.Cloud.define('hello', req => {
return 'Hi';
});

Parse.Cloud.define('asyncFunction', async req => {
Parse.Cloud.define('helloAsyncFunction', async req => {
await new Promise(resolve => setTimeout(resolve, 1000));
req.log.info(req);
return 'Hi async';
});

Parse.Cloud.beforeSave('Test', () => {
Parse.Cloud.beforeSave('TestObject', () => {
throw new Parse.Error(9001, 'Saving test objects is not available.');
});
4 changes: 3 additions & 1 deletion cloud/main.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
// It is best practise to organize your cloud functions group into their own file. You can then import them in your main.js.
await import('./functions.js');
await Promise.all([
import('./functions.js')
]);
15 changes: 15 additions & 0 deletions cloud/schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const schemaDefinitions = [{
className: "TestObject",
fields: {
beforeSave: { type: "Boolean", defaultValue: false },
additionalData: { type: "String" },
},
classLevelPermissions: {
find: { "*": true },
count: { "*": true },
get: { "*": true },
update: { "*": true },
create: { "*": true },
delete: { "*": true },
},
}];
18 changes: 18 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { schemaDefinitions } from "./cloud/schema.js";
export const config = {
databaseURI: process.env.DATABASE_URI || process.env.MONGODB_URI || 'mongodb://localhost:27017/dev',
cloud: process.env.CLOUD_CODE_MAIN || './cloud/main.js',
appId: process.env.APP_ID || 'myAppId',
masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
liveQuery: {
classNames: ['Posts', 'Comments'], // List of classes to support for query subscriptions
},
schema: {
definitions: schemaDefinitions,
lockSchemas: true,
strict: true,
recreateModifiedFields: false,
deleteExtraFields: false,
},
};
50 changes: 15 additions & 35 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,19 @@
import express from 'express';
import { ParseServer } from 'parse-server';
import path from 'path';
const __dirname = path.resolve();
import http from 'http';

export const config = {
databaseURI:
process.env.DATABASE_URI || process.env.MONGODB_URI || 'mongodb://localhost:27017/dev',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'myAppId',
masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
liveQuery: {
classNames: ['Posts', 'Comments'], // List of classes to support for query subscriptions
},
};
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// javascriptKey, restAPIKey, dotNetKey, clientKey

export const app = express();

app.set('trust proxy', true);
import { config } from './config.js';
const __dirname = path.resolve();
const app = express();

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

// Serve the Parse API on the /parse URL prefix
if (!process.env.TESTING) {
const mountPath = process.env.PARSE_MOUNT || '/parse';
const server = new ParseServer(config);
await server.start();
app.use(mountPath, server.app);
}
const mountPath = process.env.PARSE_MOUNT || '/parse';
const server = new ParseServer(config);
await server.start();
app.use(mountPath, server.app);

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

if (!process.env.TESTING) {
const port = process.env.PORT || 1337;
const httpServer = http.createServer(app);
httpServer.listen(port, function () {
console.log('parse-server-example running on port ' + port + '.');
});
// This will enable the Live Query real-time server
await ParseServer.createLiveQueryServer(httpServer);
}
const port = process.env.PORT || 1337;
const httpServer = http.createServer(app);
httpServer.listen(port, function () {
console.log('parse-server-example running on port ' + port + '.');
});
// This will enable the Live Query real-time server
await ParseServer.createLiveQueryServer(httpServer);
console.log(`Visit http://localhost:${port}/test to check the Parse Server`);
48 changes: 8 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"license": "MIT",
"main": "index.js",
"scripts": {
"coverage": "TESTING=true nyc jasmine",
"coverage": "nyc --reporter=html --reporter=text npm test",
"lint": "eslint --cache ./cloud && eslint --cache index.js && eslint --cache ./spec",
"lint-fix": "eslint --cache --fix ./cloud && eslint --cache --fix index.js && eslint --cache --fix ./spec",
"prettier": "prettier --write '{cloud,spec}/{**/*,*}.js' 'index.js'",
Expand All @@ -20,10 +20,9 @@
"watch": "nodemon index.js"
},
"dependencies": {
"axios": "1.8.1",
"express": "4.21.2",
"parse": "5.3.0",
"parse-server": "7.4.0"
"parse-server": "8.0.0-alpha.6"
},
"type": "module",
"devDependencies": {
Expand Down
Loading