【发布时间】:2020-01-24 00:21:39
【问题描述】:
如标题所述,我的网站出现“加载资源失败:net::ERR_CONNECTION_REFUSED”错误。
还有“TypeError:获取失败”和“未检查的 runtime.lastError:消息端口在收到响应之前关闭。”出于某种原因在控制台日志中。
此外,在 Heroku 上的构建日志中,它也显示“NPM_CONFIG_LOGLEVEL=error”。
据我了解,当端口没有监听任何内容时会发生这种情况。但我不确定这是怎么发生的,或者为什么会这样。
我尝试使用 process.env.NODE 而不是 env.PORT 切换端口(将其从端口 5000 更改为 3000 等)。没有变化。
这一切都基于这个 Pusher 新闻提要应用教程。这是我的 server.js 类的一些代码(假设这就是我所需要的)。
app.get('/live', (req, res) => {
const topic = 'ipo';
fetchNews(topic, 1)
.then(response => {
res.json(response.articles);
updateFeed(topic);
})
.catch(error => console.log(error));
});
app.set('port', process.env.PORT || 5000);
const server = app.listen(app.get('port'), () => {
console.log('Express running -> PORT ${server.address().port}');
});
另外,我的 app.js 代码的一小部分
componentDidMount() {
fetch('http://localhost:5000/live')
.then(response => response.json())
.then(articles => {
this.setState({
newsItems: [...this.state.newsItems, ...articles],
});
}).catch(error => console.log(error));
我不确定到底发生了什么。
【问题讨论】:
标签: node.js reactjs express heroku deployment