Struggling with connecting React front End to Express backend after deploying to Heroku

I have deployed my backend on Heroku and works fine as I send a request from POSTMAN.
I have deployed the My react app on Heroku as well.
But I can not get a response from the backend server. Please help

This is the Heroku log detail from the backend.

2020-12-30T16:45:34.688348+00:00 heroku[web.1]: Starting process with command `node index.js`
2020-12-30T16:45:37.852435+00:00 app[web.1]: Server is listening on 34248
2020-12-30T16:45:37.870603+00:00 heroku[web.1]: State changed from starting to up
2020-12-30T16:45:38.000000+00:00 app[api]: Build succeeded
2020-12-30T16:48:18.862763+00:00 heroku[router]: at=info method=OPTIONS path="/api/auth/signup" request_id=4d909f22-7fc3-4273-b010-4395adae20b7 fwd="" dyno=web.1 connect=1ms service=10ms status=204 bytes=391 protocol=https
2020-12-30T16:48:18.857570+00:00 app[web.1]: OPTIONS /api/auth/signup 204 2.315 ms - 0

Axios Instance fro Api call

import axios from "axios";

const instance = axios.create({
	withCredentials: true,

instance.defaults.headers.common['Content-Type'] ="application/json";

export default instance;

Signup action

export const signUpUser = (formData)=>{
	return dispatch => {
		// /signup"/auth/signup",formData)
		.then(res =>{
		} )
		.catch(error => {

backend index.js

const express = require("express");
const morgan = require("morgan");
const mongoose = require("mongoose");
const app = express();
const user = require("./routes/users");
const auth = require("./routes/auth");
const books = require("./routes/books");
const notFound = require("./middleware/notFound");
const errorHandler = require("./middleware/errorHandler");
const {authCheck} = require("./middleware/authCheck");
const cookieParser = require("cookie-parser");
const cors = require("cors");

//DB Connection
		useNewUrlParser: true,
		useUnifiedTopology: true,
		useCreateIndex: true
	}).catch(error =>{
		throw Error("DB connection problem")
const port = process.env.PORT||8004;

app.use("/api/user",authCheck,user);// add authcheck middleware
app.use("/api/books",authCheck, books); // add authcheck middleware
app.use( notFound);
app.use( errorHandler);

app.listen(port, ()=>{
	console.log(`Server is listening on ${port}`)

What’s the network error? As in if you go to the browser, open the network tab in the developer tools and make the call in-app, what’s the status code, response etc. I would strongly suspect a CORS error (you’re making a request from a browser, not Postman, when it fails), but I would need to know what the error is.

I got an error that failed to response to data.

Can you connect to the backend on Heroku from the client when the client runs locally?

What is the status code for the fail request?

i got this error while i am running react locally and try to connect with backend

What happens if you just use app.use(cors()) does it change anything?

Same error by using app.use(cors());

  "root": "build/",
  "routes": {
    "/**": "index.html"

this is static json file

It seems to be something in axios that is preventing the network request/error from showing (it’s giving you that JS error instead). I think the error is occurring before the network request is made, so you’re catching undefined. Then when you try to access properties on the error response, they aren’t there ( is not a thing) so you get a JS error rather than something useful. Put a catch block first and log error.toJSON() and see what that says

Yeah, you need to set up CORS properly. Have you done what it says in the error message, do you have CORS stuff added to the API app?

That issue is solved! but I can not access cookies in the backend. Do I need to add any headers?