Node.js 部署到Heroku的MERN应用程序工作不正常

Node.js 部署到Heroku的MERN应用程序工作不正常,node.js,reactjs,heroku,redux,Node.js,Reactjs,Heroku,Redux,我已经在Heroku上部署了一个MERN应用程序。当我转到应用程序时,我可以通过API将数据发布到MongoDB数据库,但是,每当我发出GET请求时,Heroku都会响应: at=info method=GET path=“/api/lists/5b44001a558fe30014e8c43c”host=bootcamp-bucket-list.herokuapp.com请求_id=e9b06431-aa30-4811-bf7d-a46720991646 fwd=“24.124.88.220”d

我已经在Heroku上部署了一个MERN应用程序。当我转到应用程序时,我可以通过API将数据发布到MongoDB数据库,但是,每当我发出
GET
请求时,Heroku都会响应:

at=info method=GET path=“/api/lists/5b44001a558fe30014e8c43c”host=bootcamp-bucket-list.herokuapp.com请求_id=e9b06431-aa30-4811-bf7d-a46720991646 fwd=“24.124.88.220”dyno=web.1 connect=0ms service=2ms status=304字节=237协议=https

我可以在我的服务器上本地运行应用程序,没有任何问题,只是在我们生产时,GET请求失败。以前有没有人经历过这种情况,并且知道是什么导致了这个问题?如果需要任何其他信息,请告诉我

下面是我的
server.js
文件的设置:

const express=require('express');
const path=require('path');
const users=require('./routes/api/users');
常量路由=需要('./路由');
常量app=express();
const port=process.env.port | | 5001;
const bodyParser=require(“body parser”);
const passport=require(‘passport’);
const mongoose=需要(“mongoose”);
常量模型=需要('./模型');
app.use(bodyParser.urlencoded({
扩展:正确
}));
use(bodyParser.json());
猫鼬。承诺=承诺;
var MONGODB_URI=process.env.MONGODB_URI |”mongodb://localhost/testdb";
log(MONGODB_URI);
mongoose.connect(MONGODB_URI);
const db=mongoose.connection;
app.use(passport.initialize());
//护照配置
要求('./配置/护照')(护照);
app.get('*',函数(req,res){
res.sendFile(path.join(uu dirname,'./client/build/index.html');
});
if(process.env.NODE_env===‘生产’){
//提供任何静态文件
应用程序使用(express.static('client/build'));
}
//使用路线
应用程序使用('/api/users',users);
应用程序使用(路线);

app.listen(端口,()=>console.log(`Listening on port${port}')您需要确保在生产模式下运行时保留api端点

app.get('*', function(req, res) {
  res.sendFile(path.join(__dirname, './client/build/index.html'));
});
应该是

if (process.env.NODE_ENV === 'production') {
  app.use(express.static('client/build')); // serve the static react app
  app.get(/^\/(?!api).*/, (req, res) => { // don't serve api routes to react app
    res.sendFile(path.join(__dirname, './client/build/index.html'));
  });
  console.log('Serving React App...');
};

事实上,我刚刚清除了缓存,现在当我访问该站点时,我得到了一个
未找到
。这是Heroku日志中出现的错误:
error:enoint:没有这样的文件或目录,stat'/app/dist/index.html'
更新了路径以反映您问题中的路径,错误是您指向index.html的路径不正确。