How can I host my own Parse Server on Heroku using MongoDB? [closed] - node.js

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
(To be clear, Im asking this question so as to provide the answer I found in an effort to help others that have been similarly affected by the Parse closure)
Parse.com recently anounced that they are closing shop January 2017 but thankfully they have made their Parse Server software open source so we can all host our own Parse server instances.
I have looked into the various options available for hosting Parse Server and have decided to host mine on Heroku
I loved Parse because it was so easy to use and I have no real experience with setting up a backend. I have tried to follow several guides online but found them all a bit hard to understand with vague steps or steps that take you down a rabbit hole on another site installing a bunch of tools and it all gets a bit confusing.
How can I host Parse Server on heroku, set it up to accept cross domain requests from my application, create a MongoDB database, and migrate all of my data from Parse to the new database?

Self hosting Parse Server on Heroku
Setup Heroku, MongoDB, and Parse
Visit https://signup.heroku.com/ and sign up for an acount
Verify your email, and log into Heroku
Go to Deploying a Parse Server to Heroku
Click "Deploy to Heroku"
Give your parse server a name
Skip the app's APP_ID and MASTER_KEY for now, we'll set that in later step.
Click "Deploy for free"
If the below box appears, enter your credit card info to verify your account. Dont worry, you wont be charged unless you upgrade your account later. This is simply a security measure Heroku has in place to prevent abuse.
Heroku will create your app. In the background it will also create a .git repo for you and clone the contents of the official parse-server-example git repo, create a MongoDB database, and configure your Heroku app to use that DB.
When the app is created, you'll be taken to it's Heroku dashboard or you can get there by logging in, clicking "Personal Apps" then clicking on the name of your parse server
On your app's dashboard, click "Settings" then click "Reveal config vars"
Fill in your app's APP_ID and MASTER_KEY. If you have an app on Parse.com now, you can use the same keys it uses. You can gey the at https://www.parse.com/apps/<APP_NAME>/edit#keys where <APP_NAME> is the name of your app. If you're creating a new app you can generate random keys here. You can add new keys for any sdks you plan to use, I'm adding one for the javascript sdk here.
Make note of the value for MONGOLAB_URI, you'll need this later if you want to migrate your existing Parse data to your new DB
Scroll down and make a note of the Git Url and the Heroku domain for your app, you'll need these later
Install the Heroku Toolbelt which is a command line interface tool for managing your Heroku apps.
Open a terminal prompt and enter $ heroku login, enter your Heroku email and password
Enter $ heroku git:clone -a <MY_APP_NAME> (where <MY_APP_NAME> is the name of your heroku app) to make a local copy of your server code repo, you can also use the git url from we saw earlier. When you clone the repo you will see the message "warning: You appear to have cloned an empty repository.". The app folder will be created but it will only contain the standard git files and no parse server. To fix this. Go to the official parse-server-example git repo, download the zip file of the repo. Extract the folder, drag all of the files and folders from the parse-server-example-master folder into your app folder.
Back in the terminal, enter $ cd <MY_APP_NAME>to move into the repo
Enable CORS (so you can use the API from other domains)
On your hard drive, find and open the local copy of the repo that we just created
In the folder, open package.json and add "cors": "*" to the dependencies like this:
.
"dependencies": {
"express": "~4.2.x",
"kerberos": "~0.0.x",
"parse": "~1.6.12",
"parse-server": "~2.0", // <= don't forget this comma
"cors": "*" // add this line
}
NOTE
Make sure to remove the above comments in your actual code as it wont be valid JSON
Open index.js and make these changes:
.
var express = require('express'); // find this line in the file
var cors = require('cors') // add this line below it
//....
//var databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_URI // old name, you may need to change this for new deployments
var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI // changed to MONGODB_URI in Heroku!
//....
var app = express(); // find this line in the file
app.use(cors()); // add this line below it
//Add declarations for any keys you plan to use as shown below
var api = new ParseServer({
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 || '',
serverURL: process.env.SERVER_URL || 'http://localhost:1337',
javascriptKey: process.env.JAVASCRIPT_KEY || '', //** add this line no need to set values, they will be overwritten by heroku config vars
restAPIKey: process.env.REST_API_KEY || '', //** add this line
dotNetKey: process.env.DOT_NET_KEY || '', //** add this line
clientKey: process.env.CLIENT_KEY || '', //** add this line
});
Go back to the terminal window, make sure you are still in the folder of the repo we cloned and enter the below to push the changes to Heroku:
.
$ git add .
$ git commit -am "make it better"
$ git push heroku master
Test your new Parse Server
Go to this jsFiddle page
Change <MY_APP_ID>,<MY_JS_KEY>,<MY_HEROKU_APP_NAME> in the fiddle to the appropriate values for your app then click "Run"
.
Parse.initialize('<MY_APP_ID>', '<MY_JS_KEY>');
Parse.serverURL = 'https://<MY_HEROKU_APP_NAME>.herokuapp.com/Parse'
You should get the below alert letting you know that your new Parse server is working correctly
NOTE:
If, you use the jsfiddle tool with multiple parse server instances, you might get the error "invalid session token". If this happens, open the dev console, and delete all of the "parse" keys from local storage, after that, it should work:
Migrate your existing data from Parse
You should do this at least once with a test app before migrating a production app. Also, it seems that legacy files from your old app may not yet transfer, see this GitHub Issue
Before we migrate, if your new MongoDB has data in it the migration will fail. If you just tested the server and created and object, go to https://dashboard.heroku.com/apps/<MY_HEROKU_APP_NAME>/resources, click "MongoLab" next to it's icon, then, on the next page, click "Delete all collections"
Go to https://dashboard.parse.com/apps/<APP_NAME>/settings/general where <APP_NAME> is the name of your parse app
Scroll down on the page and click "Migrate"
In the modal, in the grey area (that doesn't look much like an input...) enter the MONGOLAB_URI that we made note of earlier
Click "Begin the migration"
When the migration is done, click "Finalize" then, in the popup click "Okay" when the migration is final, all your data will be in your new MongoDB database.
For now, your Parse dashboard will continue to show your data that now lives in the new DB. To test everything, go back to the test jsFiddle we used before and run it again. Now, go to your Parse dashboard and you should see the newly added class and row. Note that when I used the new Parse dashboard, I could see the number of rows but the row area was all blank. I reverted to the old Parse dashboard and could see everything fine.

Related

Need to set Default Document and Physical path in Azure Web App

I am not able to see my SPA page after deploying it to Azure WebApp from VS Code. Its says
"Hey, Node developers!
Your app service is up and running.
Time to take the next step and deploy your code."
I have seen at so may site that I need to set default document and New physical path. But i don't see any Default Document Tab in Configuration menu of Web App. There are only three tabs. 1- Application Setting 2- General Setting 3- Path Mapping.
The Issue is where to set the Default document and new physical path.
If you deployed to a Node Linux Web App the default document would be hostingstart.html located in /home/site/wwwroot/.
According this document:Things You Should Know: Web Apps and Linux, there is a description about default document in a Node.js app.
When you create a Node.js app, by default, it's going to use hostingstart.html as the default document unless you configure it to look for a different file. You can use a JavaScript file to configure your default document. Create a file called index.js in the root folder of your site and add the following content.
So go to your ssh terminal, navigate to /home/site/wwwroot , create the index.js with the following code:
var express = require('express');
var server = express();
var options = {
index: 'index.html'
};
server.use('/', express.static('/home/site/wwwroot', options));
server.listen(process.env.PORT);

Parse Server Config Options In Azure

I've installed a parse.com server in Azure. All is working well with the initial setup.
I now want to lock down the server with a few of the "Advanced Options" as annotated on the Parse Server Github page.
I understand that I do these in the App Settings in Azure a la the below:
Namely, sessionLength should be visible following a server restart? However this is not the case as I still get 1 year sessions for newly logged in users. Am I filling in the details incorrectly, is there an error with Azure & Parse Server, or am I doing this completely wrong?
Im not sure if it should be SESSION_LENGTH. You would need to check to see how its constructed in the index.js.
Update:
You could try Edit the config file and pass extra params like this:
sessionLength : process.env.SESSION_LENGTH || 31536000 //Set to what you need
enableAnonymousUsers : process.env.ENABLE_ANON_USERS || false,
allowClientClassCreation: process.env.CLIENT_CLASS_CREATION || false,
github.com/mamaso/parse-server-azure-config
Look at the ENV variables listed : https://github.com/ParsePlatform/parse-server/blob/master/src/cli/definitions/parse-server.js
OR
Alternative you could update the session value on log-in or signup via a cloud code function.

Errors deploying Node.js app

So I am new to IBM Bluemix and all of their products and I am trying to do this project http://www.ibm.com/developerworks/library/ba-muse-toycar-app/index.html . I have done all of the modifying of the car and everything I am just having issues with the codes.
I have a few specific questions on part 2 step 2.b when you are entering in the information for the Cloudant database what information do I put in for the cradle connection and how do I acquire that information.
Second when I go to deploy the app Part 2 Step 2.4 how do I navigate to the application directory? I have looked at the help and googled to no avail. So if we fix these things I am hoping that I will be able to deploy the application. However currently when I go to deploy it I get this error.
cf push braincar
Updating app braincar in org ccornwe1#students.kennesaw.edu / space dev as myemailaddress#gmail.com...
OK
Uploading braincar...
FAILED
Error uploading application.
open /Users/codycornwell/.rnd: permission denied
>>
I am green to all this so any help and explanation to understand it is greatly appreciated! Thanks!
In the tutorial's part 2, step 2.b, you need to specify your Cloudant credentials. There are several ways to get Cloudant credentials, but I'll focus on doing it within the context of Bluemix and the cf command line tool.
You will first need to create a Cloudant service instance, then create a set of service keys (credentials) and then view them.
Create a Cloudant service instance named myCloudantSvc using the Shared plan:
$> cf create-service cloudantNoSQLDB Shared myCloudantSvc
Create a set of service keys (credentials) named cred1:
$> cf create-service-key myCloudantSvc cred1
View the credentials for the service key you just created
$> cf service-key myCloudantSvc creed
With the last step above, you should see output which provides you with the username, password and host values that you'll need to place into your app.js code. It should look something like the following:
{
"host": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-bluemix.cloudant.com",
"password": "longSecretPassword",
"port": 443,
"url": "https://xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-bluemix:longSecretPassword#xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-bluemix.cloudant.com",
"username": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-bluemix"
}
For your second question, it looks like you're performing the cf push from your $HOME directory (as mentioned in the comment by #vmovva). By default, the cf push command will send all files in the current directory to Bluemix/CloudFoundry.
Try running the command from the directory where your source code is located to reduce the files pushed to Bluemix. If your source code is intermingled in your $HOME directory, move your source into a different directory and then push from that directory.

How to establish a continuous deployment of non-.NET project/solution to Azure?

I have connected Visual Studio Online to my Azure website. This is not a .NET ASP.NET MVC project, just several static HTML files.
Now I want to get my files uploaded to Azure and available 'online' after my commits/pushes to the TFS.
When a build definition (based on GitContinuousDeploymentTemplate.12.xaml) is executed it fails with an obvious message:
Exception Message: The process parameter ProjectsToBuild is required but no value was set.
My question: how do I setup a build definition so that it automatically copies my static files to Azure on commits?
Or do I need to use a different tooling for this task (like WebMatrix).
update
I ended up with creating an empty website and deploying it manually from Visual Studio using webdeploy. Other possible options to consider to create local Git at Azure.
Alright, let me try to give you an answer:
I was having quite a similar issue. I had a static HTML, JS and CSS site which I needed to have in TFS due to the project and wanted to make my life easier using the continuous deployment. So what I did was following:
When you have a Git in TFS, you get an URL for the repository - something like:
https://yoursite.visualstudio.com/COLLECTION/PROJECT/_git/REPOSITORY
, however in order to access the repository itself, you need to authenticate, which is not currently possible, if you try to put the URL with authentication into Azure:
https://username:password#TFS_URL
It will not accept it. So what you do, in order to bind the deployment is that you just put the URL for repository there (the deployment will fail, however it will prepare the environment for us to proceed).
However, when you link it there, you can get DEPLOYMENT TRIGGER URL on the Configure tab of the Website. What it is for is that when you push a change to your repository (say to GitHub) what happens is that GitHub makes a HTTP POST request to that link and it tells Azure to deploy new code onto the site.
Now I went to Kudu which is the underlaying system of Azure Websites which handles the deployments. I figured that if you send correct contents in the HTTP POST (JSON format) to the DEPLOYMENT TRIGGER URL, you can have it deploy code from any repository and it even authenticates!
So the thing left to do is to generate the alternative authentication credentials on the TFS site and put the whole request together. I wrapped this entire process into the following PowerShell script:
# Windows Azure Website Configuration
#
# WAWS_username: The user account which has access to the website, can be obtained from https://manage.windowsazure.com portal on the Configure tab under DEPLOYMENT TRIGGER URL
# WAWS_password: The password for the account specified above
# WAWS: The Azure site name
$WAWS_username = ''
$WAWS_password = ''
$WAWS = ''
# Visual Studio Online Repository Configuration
#
# VSO_username: The user account used for basic authentication in VSO (has to be manually enabled)
# VSO_password: The password for the account specified above
# VSO_URL: The URL to the Git repository (branch is specified on the https://manage.windowsazure.com Configuration tab BRANCH TO DEPLOY
$VSO_username = ''
$VSO_password = ''
$VSO_URL = ''
# DO NOT EDIT ANY OF THE CODE BELOW
$WAWS_URL = 'https://' + $WAWS + '.scm.azurewebsites.net/deploy'
$BODY = '
{
"format": "basic",
"url": "https://' + $VSO_username + ':' + $VSO_password + '#' + $VSO_URL + '"
}'
$authorization = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($WAWS_username+":"+$WAWS_password ))
$bytes = [System.Text.Encoding]::ASCII.GetBytes($BODY)
$webRequest = [System.Net.WebRequest]::Create($WAWS_URL)
$webRequest.Method = "POST"
$webRequest.Headers.Add("Authorization", $authorization)
$webRequest.ContentLength = $bytes.Length
$webRequestStream = $webRequest.GetRequestStream();
$webRequestStream.Write($bytes, 0, $bytes.Length);
$webRequest.GetResponse()
I hope that what I wrote here makes sense. The last thing you would need is to bind this script to a hook in Git, so when you perform a push the script gets automatically triggered after it and the site is deployed. I haven't figured this piece yet tho.
This should also work to deploy a PHP/Node.js and similar code.
The easiest way would be to add them to an empty ASP .NET project, set them to be copied to the output folder, and then "build" the project.
Failing that, you could modify the build process template, but that's a "last resort" option.

nodejs/redis auth works locally (w/Foreman), but not on Heroku

It looks like my req.session (.user) doesn't exist when my node app is on Heroku. Things work on my local machine, and when I push to heroku, I have access to my redis-to-go store for other uses, but when I log in and proceed to authenticated pages, I get "Internal Server Error" on the served page, and "Cannot read property 'currentUser' of undefined" in the log, w/undefined = req.session, I believe.
Also, I have the same redistogo code at the start of both files:
if process.env.REDISTOGO_URL
rtg = require("url").parse(process.env.REDISTOGO_URL)
redis = require("redis").createClient(rtg.port, rtg.hostname)
redis.auth(rtg.auth.split(":")[1])
else
redis = require("redis").createClient()
edit:
I'm still rather new to Heroku/express/redis, and I realized that the problem may be that the code above isn't in the function that's being exported and called, so I moved it in, but I can't get it to deploy. After
git add .
git push heroku master
heroku releases
I get the same old list of deploys and rollbacks that I had before…
so, 1) My problem is that I had my code outside of the exported fn??
2) How do I push my changes? Have I possibly run out of memory on Heroku? my program isn't very large…
Edit2 - I figured it out. There were several small changes I needed to make.
Thanks,
John
Try changing your first line to:
if (typeof(process.env.REDISTOGO_URL) !== 'undefined')
If that doesn't work, add console.log statements to see which side of the if..else statement you're hitting on Heroku.

Resources