Ember 从 express url 提供的应用程序在刷新后无法运行

Ember app served from express urls don't work after refresh

在 ember 中,我将生产构建到我的 Express 应用程序的 /client 文件夹中。在我启动应用程序之前,在底部的 express 中,我有这些行

var api = require('./app/routes/api');

app.use('/api/v'+apiVersion, api);
app.use(express.static(__dirname + '/client'));

在我刷新页面之前一直有效,此时它 returns 为该路由 Cannot GET,在终端 morgan 的日志中我看到它正在拨打电话到 /url_here 而不是路由到 index.html 文件并允许 ember 从那里接管。我需要以不同的方式进行设置吗?

您的 Express 应用需要处理 404 错误并发送 'index.html' 客户端应用。

在最底部添加此代码(在所有其他代码下方):

app.use('/assets', express.static(__dirname + '/client/assets'));

app.use(function(req, res, next) {
  res.sendfile(__dirname + '/client/index.html');
});