无法在Heroku加载Favicon.ico进行REST API



我已经使用hapi创建了一个REST API,所有内容在本地工作正常。我尝试将其部署在heroku中,应用程序每次都在崩溃,当我检查控制台是否出现错误时,它显示了:

无法加载资源:服务器favicon.ico响应了 状态503(服务不可用(

我检查了如何处理这个问题,我发现很少有帖子说我需要添加一个端点才能返回/favicon.ico的204状态代码。我 为其创建了一个路线,如下所示:

server.route({
        method: 'GET',
        path: '/favicon.ico',
        handler: function (request, reply) {
            return reply(require('fs').createReadStream('../../favicon.ico')).code(200).type('image/x-icon');;
        }
})

再次在本地工作正常,但是在Heroku中,我遇到了同样的503错误。Heroku日志以这样的读数:

2018-02-25T04:56:18.826225+00:00 app[web.1]: Server running at: http://localhost:16689
2018-02-25T04:57:16.324815+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2018-02-25T04:57:16.324815+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-02-25T04:57:16.406578+00:00 heroku[web.1]: Process exited with
status 137
2018-02-25T04:57:16.418790+00:00 heroku[web.1]: State changed from starting to crashed
2018-02-25T06:57:16.527520+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=profileapi.herokuapp.com
request_id=16403e1b-9e90-42f0-94c9-801960806944 fwd="157.49.157.106" dyno= connect= service= status=503 bytes= protocol=https
2018-02-25T06:57:17.983629+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=profileapi.herokuapp.com request_id=67f40452-1a05-440f-962a-a045563a73af fwd="157.49.157.106" dyno= connect= service= status=503 bytes= protocol=https
2018-02-25T06:57:27.478816+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=profileapi.herokuapp.com request_id=df2d9323-aa9d-4cff-9ef8-3722efda8a2f fwd="157.49.157.106" dyno= connect= service= status=503 bytes= protocol=https
2018-02-25T06:57:28.922698+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=profileapi.herokuapp.com request_id=cc5088e6-fb7b-4c7b-8bcb-c2db8556dd8e fwd="157.49.157.106" dyno= connect= service= status=503 bytes= protocol=https

我检查了hapi-favicon,模块用户指南文档为空。我检查了它用于/favicon.ico端点的方法,我遵循它仍然遇到同样的错误。

任何人都可以有任何建议/解决此问题的建议?

问题是在创建服务器时提供的host地址,我将HOSTPORT添加到服务器连接中:

server.connection({
    host: (process.env.HOST || 'localhost'),
    port: (process.env.PORT || 1643)
});

Heroku将应用程序动态分配到端口和主机地址。我们必须使用(process.env.PORT || your_port)。同样,它将动态分配主机地址。我从连接中删除了主机。解决问题的最终连接如下:

server.connection({
    port: (process.env.PORT || 1643)
});

当我设置"引擎"时:{"节点":" 10.4.1"," npm":" 6.4.2"}