javascript - 当我使用托管在 Heroku 上的 AWS 应用程序中的数据库部署我的反应节点时,“未找到”
问题描述
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const port = process.env.PORT || 3002;
const cors = require("cors");
const path=require("path");
const routing = require("./routing/route");
require('dotenv').config();
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use("/",routing);
app.use(function (err, req, res, next) {
console.log("hii")
res.status(500).send({ message: err.message });
});
if(process.env.NODE_ENV ==="production"){
app.use(express.static("client/build"));
app.get("*",(req,res)=>{
res.sendFile(path.resolve((__dirname,"client","build","index.html")));
});
}
app.listen(port, () => {
console.log(` Server is started at http://localhost:${port}`);
});
我注意到我的后端在日志中运行我可以 Server is started at http://localhost:${port}
从我的代码中看到 //console.log( )// 这部分。
但我的前端是这样工作的。
在日志文件中,我可以看到这些错误。
TypeError: path must be absolute or specified root to res.sendFile Error: ENOENT: no such file or directory, stat '/app/index.html'
我猜这两个错误都与同一路径有关。在此处输入图像描述
我也附上了我的文件夹结构
解决方案
它与这个问题(已经有答案)非常相似- 我相信你可以在那里找到答案。
推荐阅读
- android - 谷歌商店拒绝申请
- node.js - 猫鼬正在查询另一个数据库
- python - 调整大小后获取显示的大小
- java - 调用存储过程的 Spring JPA 本机查询给出“没有找到能够从类型转换的转换器”
- java - Swagger + Spring Boot,如何基于 Spring Boot Validation 设置要在 API 中传递的示例值
- c# - 如何将直播视频从 UWP 发送到 WEB App?
- python - 如何使用 python paramiko 模块从远程服务器获取服务详细信息
- php - 使用路由参数和隐藏输入值信任用户
- sql - SQL CASE WHEN 仍在读取字段,即使它没有被使用
- java - 如何通过 JUNIT 将数据与 File 进行比较?