我已经用Node,express和Vue创建了一个基本的登录应用程序。我正在尝试将其推送到Heroku,但出现以下错误。我知道下面的文件路径不存在,所以我的问题是如何让Heroku查找:
'/ server / client / dist / index.html'
而不是下面的内容:
zYow <-404未找到136 B text / html; charset = utf-8(<—> 22.6毫秒) 错误:ENOENT:没有这样的文件或目录,统计 '/app/server/client/dist/index.html'
index.js:
const express = require("express");
const volleyball = require("volleyball");
const cors = require("cors");
const app = express();
const auth = require("./auth/index");
app.use(
cors({
origin: "http://localhost:8080"
})
);
app.use(volleyball);
app.use(express.json());
app.use(express.static(__dirname + "/client/dist/"));
app.get("/", (req, res) => {
res.sendFile(__dirname + "/client/dist/index.html");
});
app.use("/auth", auth);
function notFound(req, res, next) {
res.status(404);
const error = new Error("Not found - " + req.originalUrl);
next(error);
}
function errorHandler(err, res, next) {
res.status(res.statusCode || 500);
res.json({
message: err.message,
stack: err.stack
});
}
app.use(notFound);
app.use(errorHandler);
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log("Listening on port", port);
});