我以前曾研究过类似的问题,但没有一个解决方案为我解决,这就是为什么我要问这个问题。我只是试图将我的node.js应用程序部署到heroku,但我不断收到应用程序错误。
以下是我的日志的一部分:
2018-09-29T18:54:45.545079+00:00 app[web.1]: > pg_backend@1.0.0 start /app
2018-09-29T18:54:45.545081+00:00 app[web.1]: > node server.js
2018-09-29T18:54:45.545082+00:00 app[web.1]:
2018-09-29T18:54:46.035221+00:00 app[web.1]: listening to requests...
2018-09-29T18:55:43.134627+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2018-09-29T18:55:43.134859+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-09-29T18:55:43.317846+00:00 heroku[web.1]: Process exited with status 137
2018-09-29T18:55:43.329780+00:00 heroku[web.1]: State changed from starting to crashed
2018-09-29T21:23:23.635112+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=project-gorilla-backend.herokuapp.com request_id=2ec25806-0c83-4a7d-9bd8-eab41a67e996 fwd="131.227.39.211" dyno= connect= service= status=503 bytes= protocol=https
2018-09-29T21:23:24.637219+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=project-gorilla-backend.herokuapp.com request_id=a0582179-52fe-4c55-ba87-b0c146d66962 fwd="131.227.39.211" dyno= connect= service= status=503 bytes= protocol=https
以下是我的package.json文件:
{
"name": "pg_backend",
"version": "1.0.0",
"description": "back end application for the project gorilla site",
"main": "index.js",
"scripts": {
"start": "node server.js"
},
"engines": {
"node": "8.10.0",
"npm": "5.6.0"
},
"author": "Christopher Salay",
"license": "ISC",
"dependencies": {
"express": "^4.16.3",
"nodemailer": "^4.6.8",
"socket.io": "^2.1.1",
"vimeo": "^2.1.0"
}
}
这是我的Procfile:
web: node server.js
以下是我的server.js
let express = require('express'), app = express(), path = require('path'),
socket = require('socket.io'), emailModule = require('./email.js'),
formValidationModule = require('./formValidation.js'), vimeoModule = require('./vimeo.js'),
port = process.env.PORT || 5000;
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/index.html'));
});
let server = app.listen(port,'0.0.0.0',function(){
console.log('listening to requests...');
vimeoModule.search()
});
let io = socket(server);
io.on('connection', (socket)=>{
console.log('made a connection!');
socket.on('email', (data)=>{
if(formValidationModule.checkEmptyContact(data.client, data.email, data.name,
data.title, data.message)){
socket.emit('invalidData');
}
else {
/**
* * Here you need to set your email options which includes the clients email, destination email,
* subject and the text (the email content).
*/
emailModule.setMailOptions(data.email,/*'Info@project-gorilla.co.uk'*/'salay777@hotmail.co.uk'
, data.client + ' ' + '(' +
data.name + ')' + ' ' + data.title, data.message).then((mailOpts)=>{
emailModule.send(mailOpts)
});
console.log('email has been sent!');
}
});
});
链接到heroku应用程序:
https://pg-gorilla-backend.herokuapp.com/
并且我使用以下命令部署到heroku:
git push heroku master
答案 0 :(得分:1)
您需要在heroku上配置端口,因为在部署到heroku时无法将静态端口传递给应用程序,Heroku内置了将指定端口绑定到部署在其环境中的应用程序的方法。您需要使用env var来为应用程序分配端口。 在heroku应用程序中,您可以通过“设置”>“显示配置变量”>“在其中添加端口3000”来执行此操作,然后内置的heroku方法将为应用程序分配指定的端口号。