简体   繁体   English

MERN App 返回 index.html 而不是数据

[英]MERN App returning index.html instead of data

I don't know why the data is not returning in production mode and I just get index.html我不知道为什么数据没有在生产模式下返回,我只是得到 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"));
}

you are returning the index.html for every get request and there is no data in this code.您为每个获取请求返回 index.html 并且此代码中没有数据。

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

}); });

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问题是我的客户端路由不同于 api 路由,所以当我更正客户端代码中的路由时,数据检索没有任何问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM