我正在构建一种音乐控制器应用程序,其中我有 8 条路线,每条路线播放不同的播放列表和一个控制面板(管理员),用于控制每条路线的音量和播放状态。一切都在开发中运行良好,但在部署到 heroku 后,我在 url 上收到“应用程序错误”。当检查 heroku logs --tail 我发现这个错误:
'找不到模块'./api/room/room.routes'。
我不知道哪里出了问题,在过去的几个小时里试图弄清楚这一点。我使用反应作为前端和节点作为后端。
我的 server.js 文件 -
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const path = require("path");
const cookieParser = require("cookie-parser");
const session = require("express-session");
const app = express();
const http = require("http").createServer(app);
const io = require("socket.io")(http, {
cors: {
origin: process.env.PORT || 3030,
methods: ["GET", "POST"],
},
});
const programsRoutes = require("./api/programs/programs.routes");
const roomRoutes = require("./api/room/room.routes");
const connectSockets = require("./api/socket/SockerRoutes");
app.use(cookieParser());
app.use(bodyParser.json());
app.use(
session({
secret: "keyboard cat",
resave: false,
saveUninitialized: true,
cookie: { secure: false },
})
);
app.use(express.static(path.resolve(__dirname, "public")));
if (process.env.NODE_ENV === "production") {
} else {
const corsOptions = {
origin: [
"http://127.0.0.1:3000",
"http://localhost:3000",
"http://127.0.0.1:3030",
"http://localhost:3030",
],
credentials: true,
};
app.use(cors(corsOptions));
}
// routes
connectSockets(io);
app.use("/api/room", roomRoutes);
app.use("/api/programs", programsRoutes);
const logger = require("./services/LoggerService");
const port = process.env.PORT || 3030;
http.listen(port, () => {
logger.info("Server is running on port: " + port);
});