1

I have made a simple project where I am maintaining data of my AWS dynamoDB, on first stage I am fetching all data through db and listing items, It works perfectly when I run project on my local machine but when I deployed this on heroku it crash on hitting my node api shows 404 error here is full error screenshot

enter image description here

I have also test project to run project on static port but won't work. You can check project https://funcardmaker.herokuapp.com/update

here is my Nodejs code https://gist.github.com/amit0shakya/41a91df6cccb45665fd16b869801922e

This is heroku server log. 2019-07-30T07:59:17.593103+00:00 heroku[router]: at=info method=GET path="/getalldata" host=funcardmaker.herokuapp.com request_id=97923dda-2645-48fd-a0c5-8cf8e69b2955 fwd="139.167.184.88" dyno=web.1 connect=0ms service=5ms status=404 bytes=416 protocol=https

10
  • How do you config PORT of your NodeJS server? Commented Jul 30, 2019 at 3:18
  • @TienDuong, just in simple way const port = process.env.PORT || 8080; Commented Jul 30, 2019 at 3:21
  • I think you need to share code of your nodejs server's entry file Commented Jul 30, 2019 at 3:49
  • @TienDuong I have already shared, do you need full server js code?? here is my Nodejs code gist.github.com/amit0shakya/41a91df6cccb45665fd16b869801922e Commented Jul 30, 2019 at 4:19
  • Yeah i need your full server js code Commented Jul 30, 2019 at 4:20

1 Answer 1

1

The reason why you can't use getalldata api because you are deploying your react app instead of deploying your express server which serve your production react app. So you need to config your package.json to start express server to serve your production react app. You just need to change start script in package.json to start express instead of react.

{
  "name": "cardmaker3",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "aws-sdk": "^2.464.0",
    "axios": "^0.19.0",
    "body-parser": "^1.19.0",
    "dotenv": "^8.0.0",
    "ejs": "^2.6.1",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-redux": "^7.1.0",
    "react-router-dom": "^5.0.1",
    "react-scripts": "3.0.1",
    "redux": "^4.0.1",
    "redux-thunk": "^2.3.0"
  },
  "scripts": {
    "start-react": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "start": "node bin/config"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}
Sign up to request clarification or add additional context in comments.

5 Comments

I don't think this should be correct answer for this issue just because if I am not running express then why it is running on local system and fetching data from aws and my express server is communicating with dynamoDB and if you asking for changes in package.json then you can check my other sample which is exactly same and running on heroku amitapitest.herokuapp.com, github code : github.com/amit0shakya/apitestcode.git , this is very similar but it's working, I feel this should be routing issue on serverside, but not very sure
Please look at github.com/amit0shakya/apitestcode/blob/master/package.json. As you can see, your start script is starting express server "start": "node server",
You should know what happen on heroku and how heroku run your app. When you push your code to heroku. It run these commandd npm install npm run build npm start.
Why your app can run on local because on local you use this command npm run dev instead of npm start
thanks, I forgot that heroku always run npm start command that's why my custom script was not running on server and I was not getting result as I was expected

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.