应用程序中发生错误,无法提供您的页面将 Node.Js REST 部署到 heroku
Posted
技术标签:
【中文标题】应用程序中发生错误,无法提供您的页面将 Node.Js REST 部署到 heroku【英文标题】:An error occurred in the application and your page could not be served Deploying Node.Js REST to heroku 【发布时间】:2021-11-29 05:43:42 【问题描述】:我是使用 Heroku 部署 REST api 的新手。我已经在 Node.JS 中编写了一个 REST api,现在我想将它部署到 Heroku。请问有分步方法吗
我在 Heroku 上收到此错误
Application error
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command
heroku logs --tail
在我的桌面上,在 Postman 上测试它运行良好。但我无法从浏览器查看
https://test-restapi2.herokuapp.com/employees
我的 Node.Js 应用如下所示:
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var mysql = require('mysql');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded(
extended:true
));
app.get('/',function(req , res)
return res.send(error: true,message: 'hello')
);
var dbConn = mysql.createConnection(
host: 'xxxxxxxxxxxxxxxx',
user: 'xxxxxxxxxxxxxx',
password: 'xxxxxxxxxxx',
database: 'xxxxxxxxxxxxxxxxx'
);
dbConn.connect();
app.get('/employees',function(req,res)
dbConn.query('SELECT * FROM employeedb',function(error, results, fields)
if (error) throw error;
return res.send( error: false, data: results, message: 'users list' );
);
);
app.listen(5000,function()
console.log('App running on port 5000');
);
module.exports = app;
请问我该如何解决这个问题?
编辑
查看日志,我看到了:
2021-10-09T19:28:55.666772+00:00 heroku[web.1]: State changed from crashed to starting
2021-10-09T19:28:57.813040+00:00 heroku[web.1]: Starting process with command `npm start`
2021-10-09T19:28:59.202356+00:00 app[web.1]: npm ERR! missing script: start
2021-10-09T19:28:59.208564+00:00 app[web.1]:
2021-10-09T19:28:59.208837+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-10-09T19:28:59.208892+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-10-09T19_28_59_202Z-debug.log
2021-10-09T19:28:59.327035+00:00 heroku[web.1]: Process exited with status 1
2021-10-09T19:28:59.422562+00:00 heroku[web.1]: State changed from starting to crashed
2021-10-09T19:29:04.931511+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=test-restapi2.herokuapp.com request_id=aafd0e0b-988e-4673-9359-f7576e340d75 fwd="154.120.87.9" dyno= connect= service= status=503 bytes= protocol=https
2021-10-09T19:29:06.103970+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=test-restapi2.herokuapp.com request_id=6b375048-c8db-4323-8484-ba60aafea022 fwd="154.120.87.9" dyno= connect= service= status=503 bytes= protocol=https
2021-10-09T19:32:15.776019+00:00 app[api]: Starting process with command `npm start` by user emeka1987ng@gmail.com
2021-10-09T19:32:17.857845+00:00 heroku[run.9636]: Awaiting client
2021-10-09T19:32:17.890327+00:00 heroku[run.9636]: Starting process with command `npm start`
2021-10-09T19:32:17.959936+00:00 heroku[run.9636]: State changed from starting to up
2021-10-09T19:32:21.444257+00:00 heroku[run.9636]: Process exited with status 1
2021-10-09T19:32:21.499239+00:00 heroku[run.9636]: State changed from up to complete
2021-10-09T19:32:28.775794+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/employees" host=test-restapi2.herokuapp.com request_id=1a03731f-41cb-438d-b877-c1e49d5dd039 fwd="107.155.108.143" dyno= connect= service= status=503 bytes= protocol=https
2021-10-09T19:32:39.195421+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/employees" host=test-restapi2.herokuapp.com request_id=c1833124-6596-4401-a765-f8a65345b5e1 fwd="52.204.27.85" dyno= connect= service= status=503 bytes= protocol=https
【问题讨论】:
【参考方案1】:您可以查看应用程序的日志并确定问题。
在您的项目页面右上角,有一个“更多”按钮。 单击此处,然后单击“查看日志”,您应该能够看到确切的问题并修复它。
【讨论】:
请查看编辑 您似乎还没有在 package.json 中设置“启动”脚本。所以去那里并在“脚本”下添加“开始”:“节点 your_file_name.js” 在heroku中?还是本地文件? 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center。以上是关于应用程序中发生错误,无法提供您的页面将 Node.Js REST 部署到 heroku的主要内容,如果未能解决你的问题,请参考以下文章
将 Node.js 应用程序部署到 Heroku 的应用程序错误
尽管提供了所需的路径,如何修复“无法在您的路径中找到 Git”错误
处理您的请求时发生异常。此外,在执行自定义错误页面时发生了另一个异常
“处理您的请求时发生异常。此外,执行自定义错误页面时发生另一个异常......”