从服务器加载资源时出错:服务器在 heroku 中以 404 响应

Error loading resource from server: the server responded with 404 in heroku

提问人:Moeez Ramay 提问时间:10/12/2023 更新时间:10/12/2023 访问量:23

问:

这是我的服务器.js代码:

const jwt = require("jsonwebtoken");

const express = require("express");
const app = express();
const PORTS = process.env.PORT || 8080;
const cors = require("cors");
const router = express.Router();

router.get("/", (req, res) => {
    res.send("Server is up!");
});
module.exports = router;
const sign = require("./apis/sign");

const upload = require("./apis/upload");

const KEY = "asfasfgasghhgewgwedsgawsdg";

app.use(cors());
app.use(express.json());

//Redirects to signIn or SignUp Api's
app.use("/sign", sign);

//Redirects to upload for data submitting on found page
app.use("/upload", upload);

app.listen(PORTS, () => {
    console.log("Server started on port:", PORTS);
});

这些是我的 heroku 日志:

2023-10-12T15:52:43.964164+00:00 heroku[router]: at=info method=GET 
path="/" host=pet-finder-1-6e4ec11ea0c6.herokuapp.com request_id=90a49113-fbf7-4b1b-bb18-ea7e00b81b35 
fwd="119.155.0.144" dyno=web.1 connect=0ms service=6ms status=404 bytes=415 protocol=https

以下是一些额外的日志:

2023-10-12T15:52:47.983905+00:00 app[api]: Release v19 created by user [email protected]
2023-10-12T15:52:47.983905+00:00 app[api]: Deploy f4d731b6 by user [email protected]
2023-10-12T15:52:48.000000+00:00 app[api]: Build succeeded
2023-10-12T15:52:49.487848+00:00 heroku[web.1]: Restarting
2023-10-12T15:52:49.559516+00:00 heroku[web.1]: State changed from up to starting
2023-10-12T15:52:50.138712+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2023-10-12T15:52:50.296191+00:00 heroku[web.1]: Process exited with status 143
2023-10-12T15:52:51.902264+00:00 heroku[web.1]: Starting process with command `npm start`

我使用 nextjs 作为前端,使用 nodejs 作为后端,一切似乎都很好,但我不明白这个错误

node.js heroku next.js 服务器 路由器

评论

0赞 Martin Bean 10/13/2023
您是否已将 nodejs 构建包添加到您的 Heroku 应用程序中?部署时,是否收到显示正在为应用安装的 NPM 包的日志?
0赞 Martin Bean 10/13/2023
这回答了你的问题吗?在 heroku 上部署 nextjs fronend 和 nodejs 后端错误
0赞 Martin Bean 10/13/2023
另外,您能否不要就同一问题提出多个问题。您在这里已经有一个问题:stackoverflow.com/questions/77281310/......
0赞 Moeez Ramay 10/14/2023
我确实添加了一个构建包,添加后出现了此问题,但它没有显示正在安装的依赖项

答: 暂无答案