Heroku Cannot GET /

后端 未结 8 443
梦谈多话
梦谈多话 2020-12-03 21:08

I am new to Heroku and believe I am following all of the steps outlined on Heroku\'s website to deploy via node.js – https://devcenter.heroku.com/articles/getting-started-wi

相关标签:
8条回答
  • 2020-12-03 21:31

    I had the same issue. I finially resolved it.

    I had two folders for my code. A server folder with all my backend nodejs file and a client folder for all the front end file. That is the issue from the very beginning.

    I git init in the server folder, then git commit and git push. It didn't give me any error in the build but in the heroku logs it shows 404.

    After research for 5 hours, I figure Heroku Cannot GET / means it can't access the front end file becuase I only deployed the server folder (Duh!).

    I got rid of the server folder and moved all my backend file to the same level with client folder, changed some client file path. redid the git init , git commit, git push. Boom! everything works as expected!

    So make sure your server files are in the same level with the client folder and deploy the entire code folder.

    Hope this helps!

    0 讨论(0)
  • 2020-12-03 21:34

    I had my dist directory included in my .gitignore file so I was not committing dist to my repo and not pushing it to Heroku. Therefore, Heroku could not find any content to serve.

    I updated my .gitignore, committed, and pushed, and my app shows up just fine on Heroku now.

    0 讨论(0)
  • 2020-12-03 21:37

    I would think you haven't added the files to git. Whatever file you've edited on your local machine, you need to git add xyz.ext, git commit -m "Message", git push heroku master -u (-u will save the 'heroku master' parameters so future additions you will only need to type git push). In short, every time you're asked to deploy the app, you need to git add, git commit, git push. Hope that helps.

    0 讨论(0)
  • 2020-12-03 21:37

    I'm a little bit embarrased but my error was running git push heroku master without the changes being commited.

    0 讨论(0)
  • 2020-12-03 21:41

    Adding these two lines in server.js worked for me:

    var distDir = __dirname + "/dist/"; app.use(express.static(distDir));

    My dist structure is as follows:

    0 讨论(0)
  • 2020-12-03 21:49

    I dont know why it worked but i changed the location of my angular /dist from [root]client/dist to [root]/dist which is at the same directory level as server.js

    0 讨论(0)
提交回复
热议问题