Deployment 还原和反应:如何正确地充当Express?

Deployment 还原和反应:如何正确地充当Express?,deployment,react-router-v4,create-react-app,restify,Deployment,React Router V4,Create React App,Restify,我已经开发了一个应用程序与创建反应应用程序,我想部署它。React用于前端,Restify用于前端使用的发布API 该应用程序使用浏览器历史记录,当我刷新页面Restify时,返回JSON对象,表示路由未知 要解决此问题,Create react应用程序文档说明了如何在Express server上做好这项工作: const express = require('express'); const path = require('path'); const app = express(); ap

我已经开发了一个应用程序与创建反应应用程序,我想部署它。React用于前端,Restify用于前端使用的发布API

该应用程序使用浏览器历史记录,当我刷新页面Restify时,返回JSON对象,表示路由未知

要解决此问题,Create react应用程序文档说明了如何在Express server上做好这项工作:

const express = require('express');
const path = require('path');
const app = express();

app.use(express.static(path.join(__dirname, 'build')));

app.get('/*', function (req, res) {
  res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
这是文件:

用例 正如create react app doc中提到的,我使用restify为静态前端react app提供服务:

server.get(
  /\/(.*)?.*/,
  restify.plugins.serveStatic({
    directory: "./static",
    default: "index.html"
  })
);
Express可以,但Restify不行。对于Express,我们必须首先使用中间件来服务静态文件,然后我们必须将路由重定向到“index.html”前端应用程序。 对于Restify,我只使用了serveStatic插件,但这还不够

所以,如果你有办法解决这个问题。。。那太棒了!
thx

当您直接从浏览器访问该文件时,您是否可以尝试访问该文件?静态文件被正确地提供(css、js、index.html);React应用程序运行良好,推送历史记录浏览器正常;但刷新页面会破坏一切。可能是index.html不能作为静态文件跟踪?