Hi everyone my name is Michele and it’s the first time asking for help on this forum.
As per title I am trying to deploy the Exercise tracker on heroku but it’s not working.
I will attach some pictures of the code in the server file plus the log on heroku.
the structure of the files is 2 separate folder 1 client and the other backend.
The Error is not Found and from what I understand it doesn’t find the index html file but how?
the client side it’s been deployed on netlify and np on that side but the backend part on heroku it’s being a pain.
Server.js
const express = require('express');
const cors = require('cors');
const mongoose = require('mongoose');
const path = require('path');
require('dotenv').config();
const app = express();
const PORT = process.env.PORT || 5000
app.use(cors());
app.use(express.json());
const uri = process.env.ATLAS_URI;
mongoose.connect(uri,{useNewUrlParser:true,useCreateIndex:true,useUnifiedTopology: true});
const connection = mongoose.connection;
connection.once('open',() => {
console.log('Connection Enstablished')
})
const exercisesRouter = require('./routes/exercises');
const usersRouter = require('./routes/users');
app.use('/exercises',exercisesRouter);
app.use('/users',usersRouter);
if(process.env.NODE_ENV === "production") {
app.use(express.static('Client/build'));
app.get('*', (req,res)=>{
res.sendFile(path.join(__dirname,'build','index.html'));
} )
}
app.listen(PORT,() => {
console.log('Server up and running')
})
json file
{
"name": "backend",
"version": "1.0.0",
"main": "server.js",
"scripts": {
"start":"node server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"mongoose": "^5.9.20"
}
}
I hope someone can give me an help …