当我在Heroku上部署我的网站时,它说:
应用程序错误
应用程序中发生错误,无法提供您的页面。如果您是应用程序所有者,请检查日志以获取详细信息。您可以使用Heroku logs --tail命令从Heroku CLI执行此操作
在日志中,当我检查时,似乎没有什么大不了的。它给出:-
2020-09-20T23:56:47.790226+00:00 app[web.1]:
2020-09-20T23:56:48.040459+00:00 app[web.1]: SERVER IS RUNNIG AT PORT 8000
2020-09-20T23:56:48.040768+00:00 app[web.1]: Server runnung at http://127.0.0.1:5500
2020-09-20T23:57:44.991177+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-09-20T23:57:45.017244+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-09-20T23:57:45.087257+00:00 heroku[web.1]: Process exited with status 137
2020-09-20T23:57:45.132990+00:00 heroku[web.1]: State changed from starting to crashed
2020-09-21T02:05:44.125661+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=sheetsw.herokuapp.com request_id=b87a2aae-a1d1-44d4-9f4e-2d10421edec6 fwd="27.60.151.127" dyno= connect= service= status=503 bytes= protocol=https
2020-09-21T02:05:46.906817+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=sheetsw.herokuapp.com request_id=a46e447c-e111-4954-a6c6-a1e928013a82 fwd="27.60.151.127" dyno= connect= service= status=503 bytes= protocol=https
2020-09-21T02:06:05.637299+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=sheetsw.herokuapp.com request_id=d6aa7d9b-60eb-450c-8ceb-c063faad3917 fwd="27.60.151.127" dyno= connect= service= status=503 bytes= protocol=https
您能告诉我哪里错了,为什么吗,也请我怎样克服这个问题?
我的server.js文件:-
const express = require("express");
const fs = require('fs');
const nodemailer = require('nodemailer');
const bodyParser = require('body-parser');
/**
const port= 80;
**/
const hostname= '127.0.0.1';
const port= 5500;
const path = require('path');
const app = express();
app.get('/register.html',(req,res) => {
res.sendFile(__dirname + '/register.html')
})
/**app.use(express.static('./'));
**/
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
sending();
function sending(){
const transporter = nodemailer.createTransport({
service:'gmail',
auth:{
user:'[email protected]',
pass:'free_fire123'
}
});
function sendEmail(mail)
{
var mailOptions= {
from: '[email protected]',
to:mail.to,
subject: mail.subject,
html: mail.body
}
transporter.sendMail(mailOptions, function(err, info) {
if(err){
console.log(err+" "+mail.to)
}
else {
console.log("Email sent: "+info.response)
}
})
}
app.post('/register.html', (req,res)=> {
mail= {
to:req.body.to_address,
subject:"Sheets_Wrap - project details",
body:req.body.NAME + " ------------/////////////------------ "+ req.body.phone + " ------------/////////////------------ " + req.body.email_body + " ------------/////////////------------ " + req.body.code
}
sendEmail(mail)
res.redirect('/register.html')
})
app.listen(port, ()=> {
console.log('SERVER IS RUNNIG AT PORT 8000')
console.log(`Server runnung at http://localhost:${port}/register.html`);
})
}
问题:您的Node.js应用程序配置不正确,无法通过$ PORT环境变量绑定到Heroku提供的端口。
Heroku dynos公开了一个动态端口供您的应用绑定。此值在$ PORT env var中公开。您必须更改代码以绑定到该端口。例如:
//Replace your hardcoded port to process.env.PORT
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Our app is running on port ${ PORT }`);
});
这将使用$ PORT env var(如果可用),或使用默认端口(适用于本地开发)。请注意,在Heroku上浏览到应用程序时,您仍然使用端口80([your-application] .herokuapp.com),而不是进程绑定到的端口。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句