node.js - Heroku 错误:Web 进程在启动后 60 秒内无法绑定到 $PORT(使用 axios)
问题描述
这是完整的错误代码:Error R10 (Boot timeout) -> Web process failed to bind to $PORT in 60 seconds of launch
对此的很多答案都说它与设置你的端口有关,因为 heroku 这样做是动态的,但是如果我使用 axios 而不是 server.listen,并且需要 mcsrv api 的特定端口,我将如何解决这个问题?
我已经尝试将其设置为 process.env.PORT 无济于事(以及使用 || 语句将其设置为默认端口)
// Function for getting player counts
require('dotenv').config()
const axios = require('axios')
function pingForPlayers() {
// Ping API for server data.
axios.get(`https://api.mcsrvstat.us/2/play.lightningshot.net`)
.then(response => {
// If it gets a valid response
if(response.data && response.data.players) {
let playerCount = response.data.players.online || 0 // Default to zero
info = `${playerCount}`
client.channels.get('605543627208392875').setName("Players Online: " + info)
// Could add console.log for more info, not necessary waste of cache data
}
else
console.log('Could not load player count data for', process.env.MC_SERVER)
}).catch(err => console.log('Error pinging api.mcsrvstat.us for data:', err))
}
解决方案
推荐阅读
- python - 计算c驱动器大小时python访问被拒绝
- excel - Excel VBA 向列中的不同人员发送电子邮件
- python-3.x - 错误:在 AWS EC2 上为 Python3 安装 GDAL 时,命令“gcc”失败,退出状态为 1
- go - golang全局变量访问在基准测试中很慢
- excel - VBA 错误 13:为什么 Ubound() 中出现不匹配错误?
- mysql - Docker节点应用程序无法连接链接的mysql容器
- powershell - powershell 中的哈希表和运行空间
- java - 自动更新 JFrame 组件,无需线程或直接管理
- java - 如何使子类型的对象访问父方法?
- visual-studio-code - 在 F# 交互窗口中显示完整的字符串