[WIKI] how i deployed parse-server and parse-dashboard on mac with SSL
i was using parse-server from the first day it get open source on github, first it was really hard to understand how it works and how to deploy it and now after almost 2 years of deploying this awesome server on several Mac servers i share my knowledge of how i get this in a simple way.
Requirements
-
homebrew ( install from https://brew.sh )
-
mamp pro ( tested on ver. 4.3 )
-
ssl certificate i used the free 3 months certificate provided by comodo through https://www.gogetssl.com/domain-validation/comodo-free-ssl/ don’t forget to get the csr and key if generated online it’s important for mamp pro
-
NodeJS install using the following command in your terminal
brew install nodejs
- MongoDB install using the following command in your terminal
brew install mongodb
Setup MongoDB with — auth ( authentucation )
- create /data/db folder to save mongodb data ( you can change it to any other directory )
sudo mkdir -p /data/db
- open terminal and run the following command to start mongod instance
sudo mongod --dbpath /data/db
- if it failed to run you should stop mongodb service with brew
brew services stop mongodb
sudo mongod --dbpath /data/db
- once it run open new tab in terminal and start new mongo shell
mongo
- create new admin user (below info are demo)
use admin
db.createUser(
{
user: "imAdmin",
pwd: "admin1234",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
- close mongo shell using ctrl+c
- close mongod instance using ctrl+c
- start again mongod instance with auth this time
sudo mongod --auth --dbpath /data/db
- once it run open new tab in terminal and start new mongo shell
mongo
- now authenticate admin user
use admin
db.auth("imAdmin", "admin1234")
- let’s create parse_server user and db
use parse_db
db.createUser(
{
user: "parseUser",
pwd: "parse1234",
roles: [ { role: "readWrite", db: "parse_db" } ]
}
)
- now it’s done we have now mongodb working correctly with auhentication
Setup mamp pro with your ssl certificate
-
open mamp pro and add new host
figure 1.1 -
setup your ip and your ssl port ( be sure that’s your port is 443 )
figure 1.2 -
add your ssl certificate and it’s key, bundle ( certificate chain is your ca-bundle file )
figure 1.3
Setup parse-server-example and dashboard
- clone parse-server-example
git clone https://github.com/parse-community/parse-server-example.git ~/server
- go to the server directory and install dependencies first then install parse-dashboard
cd ~/server
npm install
npm install --save parse-dashboard
-
back to mamp pro and click on Apache tab of ( the selected host )
figure 1.4 -
Now we proxy 1337 and 4040 ports to 443 port to access parse server and dashboard through example:
https://domain_name.com/parse
rather than
https://domain_name.com:1337/parse
- inside Additional parameters for <VirtualHost> directive: field paste the following code ( change it server alias and other values to match your setup )
ServerName ParseServer
ServerAlias domain_name.com
SSLEngine on
SSLProxyEngine On
ProxyRequests Off
ProxyPass /parse http://localhost:1337/parse
ProxyPassReverse /parse http://localhost:1337/parse
ProxyPass /dashboard http://localhost:4040/dashboard
ProxyPassReverse /dashboard http://localhost:4040/dashboard
ProxyPreserveHost On
- now back to ~/server/ folder and open index.js in any text editor and remove everything inside it then put the following code inside it
// Example express application adding the parse-server module to expose Parse
// compatible API routes.
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');
var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://parseUser:parse1234@localhost:27017/parse_db',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'rh864cs8df7sdsldfrh864cs8df7sdsldf',
masterKey: process.env.MASTER_KEY || 'isfjsofghsifisfjsofghsif', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'https://domain_name.com/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
var 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
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);
// 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'));
});
var port = process.env.PORT || 1337;
var httpServer = require('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
ParseServer.createLiveQueryServer(httpServer);
// Set up parse dashboard
var dashboard = new ParseDashboard({
"apps": [{
"serverURL": 'https://domain_name.com/parse', // Not localhost
"appId": 'rh864cs8df7sdsldfrh864cs8df7sdsldf',
"masterKey": 'isfjsofghsifisfjsofghsif',
"appName": "AppNameHere",
"production": false,
}],
"users": [
{
"user":"dashboardAdmin",
"pass":"1234567890Asdfghj"
}
],
}, true);
var dashApp = express();
// make the Parse Dashboard available at /dashboard
dashApp.use('/dashboard', dashboard);
// Parse Server plays nicely with the rest of your web routes
dashApp.get('/', function(req, res) {
res.status(200).send('Parse Dashboard App');
});
var httpServerDash = require('http').createServer(dashApp);
httpServerDash.listen(4040, function() {
console.log('dashboard-server running on port 4040.');
});
- in the previous code we connect parse server to the mongodb using our admin account which have permission to readWrite on parse_db which we created early
- we added AppID and MasterKey
- we added serverURL to our new server url with ( https ) and without 1337 port
- we created ParseDashboard Instance with the configurations we have from the ParseServer.
- we set AppName for our app and put the app to development status by disabling production value
- we created ParseDashboard admin user which will access the dashboard through it’s authentication system
NOTE
if you need it without SSL ( you need to change 443 port to 80 in MAMP PRO ) and replace ( https ) to => ( http ) in your ~/server/index.js files
Great tutorial for setting up parse on a local machine. One thing you forgot was to require ParseDashboard in your index.js ‘const ParseDashboard = require(‘parse-dashboard’);’