Home > OS >  MERN App returning index.html instead of data
MERN App returning index.html instead of data

Time:12-29

I don't know why the data is not returning in production mode and I just get index.html

app.use("/api/auth", authRoute);
app.use("/api/users", userRoute);
app.use("/api/movies", movieRoute);
app.use("/api/lists", listRoute);
app.use("/api/check-existance", verify);
app.use("/api/matches", matchRoute);
app.use("/api/categories", categoryRoutes);
app.use("/api/subCategories", subCategoryRoutes);
app.use("/api/competetions", competetionRoutes);
app.use("/api/stream", videos);

if (process.env.NODE_ENV === "production") {
  app.use(express.static(path.join(__dirname, "../client/build")));

  app.get("/*", (req, res) => {
    res.sendFile(path.join(__dirname, "../client", "build", "index.html"));
  });
} else {
  app.get("/", (req, res) => res.send("Please set to production"));
}

CodePudding user response:

you are returning the index.html for every get request and there is no data in this code.

app.get("/*", (req, res) => {
   res.sendFile(path.join(__dirname, "../client", "build", "index.html"));

});

CodePudding user response:

The Problem was that my client routes are differed from api routes, So when I corrected the routes in client code the data retrieve without any problem

  • Related