【发布时间】:2021-10-29 07:39:21
【问题描述】:
我有一个 app.js 节点主文件,我在其中定义我的 api 路径如下
app.get('/api/users', UserController.get);
在同一个文件下面我有以下内容
app.use(express.static(path.resolve(__dirname, "./front/build")));
app.get("*", function (request, response) {
response.sendFile(path.resolve(__dirname, "./front/build", "index.html"));
});
index.html 成功服务于 React App。
如果我在 my-app.herokuapp.com 的某个地方打开我的 heroku 应用程序,它将打开预期的 React 应用程序,但问题是 my-app.herokuapp.com/api/users 还提供 index.html 文件而不是端点应该返回的 JSON。
我试过了
我将端点路由定义替换为“”定义之前(还不够)
更重要的是,我删除了对 index.html 的重定向,但 heroku 仍然使用任何类型的请求打开 index.html 页面(“”重定向仍然有效)。那么,它可能缓存了一些东西?
是关于缓存(如何清理?)还是任何其他建议?
【问题讨论】:
标签: node.js reactjs heroku heroku-cli nodejs-server