Home > Net >  Heroku Cannot GET/
Heroku Cannot GET/

Time:04-20

I deployed my project with Heroku and everything works correctly but when I refresh the page I received the error "Cannot GET /home". Is there anyone can help me? https://fresh-bio.herokuapp.com/

server.js:

require("dotenv").config();
const express = require("express");
const cors = require("cors");
const app = express();
const connectDB = require("./config/connectDB");
const routesProducts = require("./routes/productsRoutes");
const routesUsers = require("./routes/userRoutes");

app.use(express.json());
app.use(cors());
connectDB();
app.use("/api/products", routesProducts);
app.use("/api/users", routesUsers);
app.use(express.static("client/build"));

app.get("/", function (req, res) {
  res.sendFile("client/build/index.html");
});
if (process.env.NODE_ENV === "production") {
  app.use(express.static("client/build"));
}

const PORT = process.env.PORT || 5000;
app.listen(process.env.PORT, (err) =>
  err
    ? console.error(err.message)
    : console.log(`This server is running on localhost:${process.env.PORT}...`)
);

CodePudding user response:

require("dotenv").config();
const express = require("express");
const cors = require("cors");
const app = express();
const connectDB = require("./config/connectDB");
const routesProducts = require("./routes/productsRoutes");
const routesUsers = require("./routes/userRoutes");

app.use(express.json());
app.use(cors());
connectDB();
app.use("/api/products", routesProducts);
app.use("/api/users", routesUsers);
app.use(express.static(__dirname   "/client/build/"));
app.get(/.*/, (req, res) => {
  res.sendFile(__dirname   "/client/build/index.html");
});


const PORT = process.env.PORT || 5000;
app.listen(process.env.PORT, (err) =>
  err
    ? console.error(err.message)
    : console.log(`This server is running on localhost:${process.env.PORT}...`)
);
  • Related