I'm trying to deploy an app created with the MERN stack on Heroku.
The structure of my app:
the port for the Back-end (Node.js server) is created in server.js
:
const port = process.env.PORT || 80;
app.listen(port, () => console.log(`Server running on port ${port}`));
I added a proxy to my client's package.json:
I haven't added the environmental variable PORT to Config Vars inside the Heroku panel (I only have added mongoURI and REACT_APP_API_KEY):
As I understand, each time in Heroku a dynamic port is created for the server:
Inside the 'client' part of the app (where all React.js files are kept) I'm calling a Back-end endpoint, e.g:
However, once the app is deployed (it is built successfully), in the Network tab I can see that the request is being made to http://localhost/pagesWithMovies/1
.
How to use the dynamic PORT assigned by Heroku instead? Thanks