无法在 heroku 中加载 favicon.ico 休息 api
Unable to load favicon.ico for rest api in heroku
我使用 hapi
创建了一个 REST api,在本地一切正常。我尝试在 heroku
中部署它,应用程序每次都崩溃,当我检查控制台是否有错误时,它显示:
Failed to load resource: the server favicon.ico responded with a
status of 503 (Service Unavailable)
我检查了如何处理这个问题,我发现很少有帖子说我需要将一个端点添加到 return /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
端点的方式,我按照它仍然得到同样的错误。
谁能suggestion/way解决这个问题?
问题出在创建服务器时提供的 host
地址,我将 HOST
和 PORT
添加到服务器连接,如下所示:
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)
});
当我设置 "engines" 时:{
"node":"10.4.1",
"npm":“6.4.2”
}
我使用 hapi
创建了一个 REST api,在本地一切正常。我尝试在 heroku
中部署它,应用程序每次都崩溃,当我检查控制台是否有错误时,它显示:
Failed to load resource: the server favicon.ico responded with a status of 503 (Service Unavailable)
我检查了如何处理这个问题,我发现很少有帖子说我需要将一个端点添加到 return /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
端点的方式,我按照它仍然得到同样的错误。
谁能suggestion/way解决这个问题?
问题出在创建服务器时提供的 host
地址,我将 HOST
和 PORT
添加到服务器连接,如下所示:
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)
});
当我设置 "engines" 时:{ "node":"10.4.1", "npm":“6.4.2” }