Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"no-await-in-loop" : 1
},
"globals" : {
"Parse" : true
"Parse" : true,
"document": true
}
}
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Example project using the [parse-server](https://github.com/ParsePlatform/parse-
# Table of Contents <!-- omit in toc -->

- [Local Development](#local-development)
- [File Setup](#file-setup)
- [Helpful Scripts](#helpful-scripts)
- [Remote Deployment](#remote-deployment)
- [Heroku](#heroku)
Expand Down Expand Up @@ -39,6 +40,16 @@ Example project using the [parse-server](https://github.com/ParsePlatform/parse-
* You now have a database named "dev" that contains your Parse data
* Install ngrok and you can test with devices

## File Setup
Feel free to change this at your discretion. Example projects are just that - an example.

* `/spec` contains unit tests you can write to validate your Parse Server.
* `/src/cloud` contains Parse.Cloud files to run custom cloud code.
* `/src/public` contains public assets.
* `/src/views` contains views that express can render.
* `/src/config.js` contains all Parse Server settings.
* `index.js` is the main entry point for `npm start`, and includes express routing.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename index to server.js

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it’s pretty common practise for index to be the main entry point for package.json


## Helpful Scripts
These scripts can help you to develop your app for Parse Server:

Expand Down Expand Up @@ -83,7 +94,7 @@ Detailed information is available here:

## Google App Engine

1. Clone the repo and change directory to it
1. Clone the repo and change directory to it
1. Create a project in the [Google Cloud Platform Console](https://console.cloud.google.com/).
1. [Enable billing](https://console.cloud.google.com/project/_/settings) for your project.
1. Install the [Google Cloud SDK](https://cloud.google.com/sdk/).
Expand Down Expand Up @@ -164,9 +175,11 @@ curl -X POST \

### JavaScript

We have built an example page to show JS SDK usage, available at [http://localhost:1337/](http://localhost:1337/).

```js
// Initialize SDK
Parse.initialize("YOUR_APP_ID", "unused");
Parse.initialize("YOUR_APP_ID");
Parse.serverURL = 'http://localhost:1337/parse';

// Save object
Expand Down
51 changes: 13 additions & 38 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
// Example express application adding the parse-server module to expose Parse
// compatible API routes.

const express = require('express');
const ParseServer = require('parse-server').ParseServer;
const path = require('path');
import express from 'express';
import { ParseServer } from 'parse-server';
import { createServer } from 'http';
import { config } from './src/config.js';
import { renderFile } from 'ejs';
const args = process.argv || [];
const test = args.some(arg => arg.includes('jasmine'));

const databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;

if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}
const config = {
databaseURI: databaseUri || '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

const app = express();
export const app = express();
app.set('view engine', 'ejs');
app.engine('html', renderFile);
app.set('views', `./src/views`);

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

// Serve the Parse API on the /parse URL prefix
const mountPath = process.env.PARSE_MOUNT || '/parse';
Expand All @@ -40,26 +26,15 @@ if (!test) {

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

// There will be a test page available on the /test path of your server url
// Remove this before launching your app
app.get('/test', function (req, res) {
res.sendFile(path.join(__dirname, '/public/test.html'));
res.render('test.html', { appId: config.appId, serverUrl: config.serverURL });
});

const port = process.env.PORT || 1337;
if (!test) {
const httpServer = require('http').createServer(app);
const httpServer = createServer(app);
httpServer.listen(port, function () {
console.log('parse-server-example running on port ' + port + '.');
console.log(`parse-server-example running on port ${port}.`);
});
// This will enable the Live Query real-time server
ParseServer.createLiveQueryServer(httpServer);
}

module.exports = {
app,
config,
};
31 changes: 17 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,37 @@
},
"license": "MIT",
"dependencies": {
"ejs": "3.1.6",
"express": "4.17.1",
"kerberos": "1.1.4",
"parse": "2.19.0",
"parse-server": "4.5.0"
"kerberos": "1.1.6",
"parse": "3.3.0",
"parse-server": "4.10.3"
},
"scripts": {
"start": "node index.js",
"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",
"lint": "eslint --cache ./src && eslint --cache index.js && eslint --cache ./spec",
"lint-fix": "eslint --cache --fix ./src && eslint --cache --fix index.js && eslint --cache --fix ./spec",
"test": "mongodb-runner start && jasmine",
"test:kill": "kill $(lsof -ti:27017) && npm test",
"coverage": "nyc jasmine",
"prettier": "prettier --write '{cloud,spec}/{**/*,*}.js' 'index.js'",
"prettier": "prettier --write '{src,spec}/{**/*,*}{.js,.html,.css}' 'index.js'",
"watch": "babel-watch index.js"
},
"engines": {
"node": ">=4.3"
},
"type": "module",
"devDependencies": {
"babel-eslint": "10.1.0",
"babel-watch": "7.4.0",
"eslint": "7.19.0",
"eslint-config-standard": "16.0.2",
"eslint-plugin-import": "2.22.1",
"babel-watch": "7.5.0",
"eslint": "7.32.0",
"eslint-config-standard": "16.0.3",
"eslint-plugin-import": "2.24.2",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "4.2.1",
"jasmine": "3.6.4",
"mongodb-runner": "4.8.1",
"eslint-plugin-promise": "5.1.0",
"jasmine": "3.9.0",
"mongodb-runner": "4.8.3",
"nyc": "15.1.0",
"prettier": "2.2.1"
"prettier": "2.3.2"
}
}
Loading