首页 > 解决方案 > 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))

}

标签: node.jsherokudiscorddiscord.js

解决方案


您的应用不是网络应用。

您可以Procfile在源中添加:

worker:  node index.js // (or your main file)

并更改为工人:

  • 在 Heroku 仪表板中,单击选项卡资源
  • 在此处输入图像描述并启用工人

推荐阅读