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

Create AWS secrets branch #402

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
}
}
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
node-version: [15.x]
name: ${{ matrix.name }}
steps:
- uses: actions/checkout@v2
Expand Down
36 changes: 33 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
[![License][license-svg]][license-link]
[![Twitter Follow](https://img.shields.io/twitter/follow/ParsePlatform.svg?label=Follow%20us%20on%20Twitter&style=social)](https://twitter.com/intent/follow?screen_name=ParsePlatform)

Example project using the [parse-server](https://github.com/ParsePlatform/parse-server) module on Express. Read the full [Parse Server Guide](https://docs.parseplatform.org/parse-server/guide/) for more information.
Example project using the [parse-server](https://github.com/ParsePlatform/parse-server) module on Express, utilising AWS Secret Manager Read the full [Parse Server Guide](https://docs.parseplatform.org/parse-server/guide/) for more information.

Please note: this example uses top level await which is only available in Node >= v14.8.0.

# Table of Contents <!-- omit in toc -->

- [Local Development](#local-development)
- [Creating AWS Secrets](#creating-aws-secrets)
- [File Setup](#file-setup)
- [Helpful Scripts](#helpful-scripts)
- [Remote Deployment](#remote-deployment)
- [Heroku](#heroku)
Expand All @@ -29,6 +33,20 @@ Example project using the [parse-server](https://github.com/ParsePlatform/parse-

# Local Development

## Creating AWS Secrets
* Log into the AWS Console and navigate to AWS Secrets Manager
* Click "store a new secret"
* Select "other type of secret"
* Enter the initial secret value
* Name the secret (`/src/config` will reference this secret name). If you have selected key pairs, make sure you properly destructure the returned secret.
* If you would like to automatically rotate the key, follow [this](https://docs.aws.amazon.com/secretsmanager/latest/userguide/rotate-secrets_turn-on-for-other.html) guide.


## Local Development

* Install AWS SDK with `npm install aws-sdk -g`
* Create an AWS profile with `aws configure --profile profileName`
* Update `npm start`'s `AWS_Profile` and `AWS_REGION`
* Make sure you have at least Node 4.3. `node --version`
* Clone this repo and change directory to it.
* `npm install`
Expand All @@ -39,6 +57,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.

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

Expand Down Expand Up @@ -83,7 +111,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 +192,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
70 changes: 19 additions & 51 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,33 @@
// 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');
const args = process.argv || [];
const test = args.some(arg => arg.includes('jasmine'));
import express from 'express';
import { ParseServer } from 'parse-server';
import { createServer } from 'http';
import { config } from './src/config.js';
import { renderFile } from 'ejs';

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')));

// Serve the Parse API on the /parse URL prefix
const mountPath = process.env.PARSE_MOUNT || '/parse';
if (!test) {
const api = new ParseServer(config);
app.use(mountPath, api);
}
app.use('/public', express.static('./src/public'));

// 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!');
app.get('/', (req, res) => {
res.render('test.html', { appId: config.appId, serverUrl: config.serverURL });
});

// 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'));
});
if (!process.env.TESTING) {
const api = new ParseServer(config);
app.use('/parse', api);

const port = process.env.PORT || 1337;
if (!test) {
const httpServer = require('http').createServer(app);
httpServer.listen(port, function () {
console.log('parse-server-example running on port ' + port + '.');
const httpServer = createServer(app);
const port = 1337;
httpServer.listen(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,
};
36 changes: 20 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,38 @@
},
"license": "MIT",
"dependencies": {
"aws-sdk": "2.994.0",
"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",
"test": "mongodb-runner start && jasmine",
"start": "AWS_PROFILE=aws_profile AWS_REGION=aws_region node index.js",
"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 && TESTING=true 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