我是新手编码,但目前正在学习,因为我想在我的脸书页面上创建一个聊天机器人。 Belows是我在每个.js中的脚本和我之后遇到的错误。输入heroku后,网络显示“应用程序错误 应用程序中发生错误,无法提供您的页面。如果您是应用程序所有者,请检查日志以获取详细信息。“
希望有人可以帮助我,非常感谢!
index.js
var express = require('express')
var bodyParser = require('body-parser')
var request = require('request')
var app = express()
app.set('port', (process.env.PORT || 5000))
// Process application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({extended: false}))
// Process application/json
app.use(bodyParser.json())
// Index route
app.get('/', function (req, res) {
res.send('Hello world, I am a chat bot')
})
// for Facebook verification
app.get('/webhook/', function (req, res) {
if (req.query['hub.verify_token'] === 'my_voice_is_my_password_verify_me') {
res.send(req.query['hub.challenge'])
}
res.send('Error, wrong token')
})
// Spin up the server
app.listen(app.get('port'), function() {
console.log('running on port', app.get('port'))
})
的package.json
{
"name": "node",
"version": "1.0.0",
"description": "facebook chatbot",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "krix",
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.1",
"express": "^4.15.4",
"request": "^2.81.0"
}
}
Procfile.json
web: node index.js
heroku日志:
2017-09-14T13:32:53.277012+00:00 app[api]: Release v2 created by user network.of.eden@gmail.com
2017-09-14T13:32:53.277012+00:00 app[api]: Enable Logplex by user network.of.eden@gmail.com
2017-09-14T13:32:53.049614+00:00 app[api]: Initial release by user network.of.eden@gmail.com
2017-09-14T13:32:53.049614+00:00 app[api]: Release v1 created by user network.of.eden@gmail.com
2017-09-14T13:33:16.000000+00:00 app[api]: Build started by user network.of.eden@gmail.com
2017-09-14T13:33:44.501803+00:00 app[api]: Release v3 created by user network.of.eden@gmail.com
2017-09-14T13:33:44.550885+00:00 app[api]: Scaled to web@1:Free by user network.of.eden@gmail.com
2017-09-14T13:33:44.501803+00:00 app[api]: Deploy 30d98ae9 by user network.of.eden@gmail.com
2017-09-14T13:33:16.000000+00:00 app[api]: Build succeeded
2017-09-14T13:33:47.445193+00:00 heroku[web.1]: Starting process with command `npm start`
2017-09-14T13:33:51.208413+00:00 app[web.1]:
2017-09-14T13:33:51.208690+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2017-09-14T13:33:51.208802+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2017-09-14T13_33_51_189Z-debug.log
2017-09-14T13:33:51.186998+00:00 app[web.1]: npm ERR! missing script: start
2017-09-14T13:33:51.326957+00:00 heroku[web.1]: State changed from starting to crashed
2017-09-14T13:33:51.329410+00:00 heroku[web.1]: State changed from crashed to starting
2017-09-14T13:33:51.312231+00:00 heroku[web.1]: Process exited with status 1
2017-09-14T13:33:53.384440+00:00 heroku[web.1]: Starting process with command `npm start`
2017-09-14T13:33:56.553788+00:00 app[web.1]: npm ERR! missing script: start
2017-09-14T13:33:56.567775+00:00 app[web.1]:
2017-09-14T13:33:56.567944+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2017-09-14T13:33:56.567995+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2017-09-14T13_33_56_555Z-debug.log
2017-09-14T13:33:56.688362+00:00 heroku[web.1]: Process exited with status 1
2017-09-14T13:33:56.703579+00:00 heroku[web.1]: State changed from starting to crashed
2017-09-14T13:34:34.169385+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=boiling-fortress-15768.herokuapp.com request_id=d93942a9-fddf-426c-8604-39aaf8abe6a7 fwd="58.153.46.198" dyno= connect= service= status=503 bytes= protocol=https
2017-09-14T13:34:34.510184+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=boiling-fortress-15768.herokuapp.com request_id=8b2d01d7-56f8-453b-a355-d58c9fd6ca85 fwd="58.153.46.198" dyno= connect= service= status=503 bytes= protocol=https
2017-09-14T13:37:20.203744+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=boiling-fortress-15768.herokuapp.com request_id=884f9ef7-b7f9-4f49-bd57-6b509ec90f6f fwd="58.153.46.198" dyno= connect= service= status=503 bytes= protocol=https
2017-09-14T13:37:20.530728+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=boiling-fortress-15768.herokuapp.com request_id=3ae40dba-5f53-4436-a406-1c45b6bab5af fwd="58.153.46.198" dyno= connect= service= status=503 bytes= protocol=https
我已经尝试并阅读了其他人在github上提出的很多问题,但我仍然无法解决问题。我从以下网站学习了设置nodejs和heroku服务器的方法:https://chatbotsmagazine.com/have-15-minutes-create-your-own-facebook-messenger-bot-481a7db54892
我真诚地希望有人能帮我解决问题,非常感谢你!
答案 0 :(得分:0)
Procfile文件名应该只是Procfile
,我看到你的文件名似乎是Procfile.json
,可能是它。
但是当你的package.json有启动脚本时,只需确保你有git添加所有文件并在推送到Heroku之前提交它们
答案 1 :(得分:0)
这听起来可能重复,但相信我不是。我正在做一门课程,其中 100 人(如果不是数千人)有同样的问题。如果您遇到此错误,请查看以下内容。
在你的 package.json 文件中,确保你在脚本中提到了 "start": "node app.js" 以及 "licence" 下的“engines”。这是我的 package.json 的示例代码正在工作:
{
"name": "todolist-v1",
"version": "1.0.0",
"description": "todolist",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"author": "Armaghan",
"license": "ISC",
"engines": {
"node": "14.15.3"
},
"dependencies": {
"body-parser": "^1.19.0",
"ejs": "^3.1.5",
"express": "^4.17.1",
"jquery": "^3.5.1",
"lodash": "^4.17.20a",
"mongoose": "^5.11.14",
"nodemon": "^2.0.7"
}
}
为了确保您添加了正确版本的节点,请在终端中使用此命令来显示您当前的节点版本。 node --version
将 app.listen 代码替换为以下 Heroku 应用部署代码:
let port = process.env.PORT;
if (port == null || port == "") {
port = 3000;
}
app.listen(port, function() {
console.log("Server started succesfully");
});
确保您提交了正确的 git 分支。我忘记提交一个不同的(实验性)分支,它在 package.json 文件中没有更新的更改。要检查您当前的 git 存储库分支,请使用 git branch
分支显示后,您可以使用 git checkout branchname
在分支之间切换
就我而言,我想提交 master,所以我首先使用 git branch master
进入 master,然后使用
git add .
(空格后包含点)。
然后使用 git commit -m "your comment"
最后使用以下命令再次将其推送到 Heroku 服务器上。
git push heroku master
推送完成后,最好在到达互联网上的网络应用地址之前给它几分钟时间,因为这可能需要一些时间来启动和运行。
亲切的问候,