Latest Event Updates
I was getting the error : TypeError: Cannot read property ‘request’ of undefined while I was building a react lab.
I noticed it said something about components not installed. I had ran npm install before but that wasn’t the fix.
yarn install is what fixed it, looks like some packages depended on yarn rather than npm.
Looks like I will need a buildpack for it to deploy. This is so Heroku can understand what type of app it has.
Solution1: Just deploy it as a github page.
Since its a static site, there is nothing “serving” index.html, and heroku is a cloud platform, hosting apps, not a “webhost” in the web 2.0 sense.
Since I want to keep everything on heroku for now, lets see what else we can do.
Attempted Solution: rename index.html to index.php
The least effort solution is to rename your default file to index.php and redeploy. Heroku will detect it as a PHP site and use that buildpack. – John Beynon
Very curious! Would this work? Why not try it out.
hmm appears to work! I was going to deploy a sinatra app or ry the heroku static bundle and I will probably do that anyway but this quick solution can be a real timesaver!
Go to your Heroku Dashboard. Click “new”-> “create new app”
Give your app a name and click “Create app”
There are several ways to deploy
- Heroku CLI – push your project up to Heroku from your command line
- Github – Heroku is connected to github, so everytime github is updated your app is
- Dropbox connected
- Container Registry
We will be using Heroku CLI. If you need to install use these instructions
By default Heroku ONLY supports the master branch. If you want to push up a branch other than master follow these instructions.
Add Heroku as a remote to your project
heroku git:remote -a name-of-your-heroku-app
Push your project to Heroku
git push heroku master
Did you just get an error? Did you use sqlite3 for your project?
remote: An error occurred while installing sqlite3 (1.3.13), and Bundler cannot
remote: Make sure that `gem install sqlite3 -v ‘1.3.13’` succeeds before bundling
remote: In Gemfile:
remote: ! Failed to install gems via Bundler.
Migrate and seed your database
In your command line run the following commands.
heroku run rake db:migrate
heroku run rake db:seed
Test your API using Postman
To get the address, just go back to the Heroku dashboard and click on “Open app” to get the link to your online api
If you made it this far, your API should be deployed and now test it as you did locally (you did test locally didn’t you???).
The reason you need postman is if you setup your Rails API correctly when you query your site via browser you should get an error
This appname-api.herokuapp.com page can’t be found
but if you connect to it via postman you should get back the appropriate response
Your mod 3 and 4 projects were probably done using sqlite3. If you did your mod5 project in sqlite3, tsk tsk!
- edit your Gemfile
- comment out sqlite and add gem pg
- run “bundle install”
- Change your databases names, as below.
rake db:seed(if you have a seed file)
- Now test your app, and you are now using Postgres!
How do I know that it worked?
- Go to the little Postgres elephant, and click him
- Press stop
- If your site does not work, then you migrated successfully. Refresh your browser if needed
- Now start up Postgres so you can continue developing!
Strange news on heroku, one of my heroku apps was not working even though nothing had changed.
This nameofmyapp-api.herokuapp.com page can’t be found
No webpage was found for the web address: https: // nameofmyapp-api.herokuapp.com/HTTP ERROR 404
The problem doesn’t appear to be an app issue, rather a DNS issue.
Last I had checked it, it was working fine. I had used it on and off for several days. After about a week, I came back to it and found it in this state. I even clicked the app from the “Open app” tab in heroku. I don’t want to rename the app to see if it would work, because I should not have to do that.
- Dynos restarted
- Heroku log checked.
- Run postman against the API
Then I realize that I am looking at the API version of the app, not the similarly named frontend.
The api doesn’t respond to requests at the top level route. That is by design. The front end is named https://nameofmyapp-app.herokuapp.com/ similar to https://nameofmyapp-api.herokuapp.com/.
Ways to prevent this in the future:
- Add “API” to the beginning of the name rather then the end.
- Add custom domain to the front end
- READ CAREFULLY!
Was a weird error.I build fully functioning apps locally before deployment. Locally when running rails server, this error never came up.
When I deployed the app to heroku, I then started receiving that error.
I thought adding “require ‘jwt'” might help, but it didn’t.
This comment by MikaOY pointed me in the right direction:
“Turns out it isn’t a problem with the AuthO implementation, just that libs/ is not included by auto-loaded by default in some versions of Rails.”
Well, I looked in application.rb and I was already autoloading lib. But it pushed me in the right direction.
I specifically had to require_relative the rb file that contained JsonWebToken. Still looking into why that is so, especially since I have a working instance locally. It could just be something with heroku. But hope this helped someone.
I completed a React project with a Rails API backend. Locally everything worked prefectly. When trying to change environment variables like the address of the API backend, I wanted to create a seperate branch for heroku, it case I needed to edit something for heroku. I would rather not clutter “master” with changes until they are 100% working.
Problem is heroku only recognizes master branches, but to test I need to commit to master
Well there is a work aorund, just push a different branch up to heroku manually
git push heroku [name-of-your-branch]:master
this way I can push up a branch I named heroku up to heroku.