是什么原因导致我部署的Heroku应用程序无法打开



所以,我正在将我的聊天应用程序部署到Heroku,我想测试我的Socket.io套接字是否正常工作。无论如何,我无法让heroku open工作。我安装了serve-favicon中间件来提供帮助,但这似乎并没有起到作用。有什么想法吗?

server.js

var app = require('express')();
var http = require('http').createServer(app);
var io = require('socket.io')(http);
var path = require('path');
const favicon = require('serve-favicon');
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
let port = process.env.PORT;
if (port == null || port == "") {
port = 8000;
}
app.listen(port);
app.get('/', (req, res) => {
res.sendFile(__dirname + '/public/index.html');
});
io.on('connection', (socket) => {
socket.on('userJoin', (user) => {
console.log('User connected to room');
})
console.log('a user connected');
});

http.listen(3001, () => {
console.log('listening on port 3001');
});

Procfile

web: node server.js
web: npm start

插座

import io from 'socket.io-client'
let socket;
export const initSocket = () => {
socket = io('http://localhost:3001')
console.log('initializing socket')
}

错误

2020-10-22T00:12:31.056919+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=thawing-everglades-25591.herokuapp.com request_id=6647c4af-3d55-4923-a2a1-27426e589146 fwd="184.167.78.55" dyno= connect= service= status=503 bytes= protocol=https
2020-10-22T00:12:31.317690+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=thawing-everglades-25591.herokuapp.com request_id=570c5025-8b0e-4789-b191-3783e37fac2d fwd="184.167.78.55" dyno= connect= service= status=503 bytes= protocol=https

Heroku上的日志

2020-10-22T00:04:39.557182+00:00 app[web.1]: [34mℹ[39m [90m「wds」[39m: 404s will fallback to /
2020-10-22T00:04:39.557588+00:00 app[web.1]: Starting the development server...
2020-10-22T00:04:39.557590+00:00 app[web.1]: 
2020-10-22T00:04:39.698176+00:00 heroku[web.1]: Process exited with status 0
2020-10-22T00:04:39.745109+00:00 heroku[web.1]: State changed from starting to crashed
2020-10-22T00:12:31.056919+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=thawing-everglades-25591.herokuapp.com request_id=6647c4af-3d55-4923-a2a1-27426e589146 fwd="184.167.78.55" dyno= connect= service= status=503 bytes= protocol=https
2020-10-22T00:12:31.317690+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=thawing-everglades-25591.herokuapp.com request_id=570c5025-8b0e-4789-b191-3783e37fac2d fwd="184.167.78.55" dyno= connect= service= status=503 bytes= protocol=https
2020-10-22T00:18:58.529683+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=thawing-everglades-25591.herokuapp.com request_id=c349aa37-bb68-4bcc-b065-899220a3fbe8 fwd="54.83.117.30" dyno= connect= service= status=503 bytes= protocol=http
2020-10-22T00:27:34.585166+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=thawing-everglades-25591.herokuapp.com request_id=0bee0800-8f3d-4e3a-b3fe-c85e5271d1b2 fwd="184.167.78.55" dyno= connect= service= status=503 bytes= protocol=https
2020-10-22T00:27:34.856060+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=thawing-everglades-25591.herokuapp.com request_id=4ac98349-5d06-4c0d-af86-94e08a1e1193 fwd="184.167.78.55" dyno= connect= service= status=503 bytes= protocol=https

Heroku/Netflify应该能够使用";npm启动";在构建时,你的应用程序应该检查它是否在生产中,设置端口,你的服务器(用于react(应该提供构建文件夹,该文件夹将有自己的index.html和所有相关文件,如你的favicon react,应该在构建时处理。

检查您的设置,通常像Heroku/Netlify这样的服务会在生产环境中通过。这是一个旧项目的片段。我最近没有在Heroku上主持任何节目,但希望这能有所帮助。

// Serve static assests in production (serve react)
if (process.env.NODE_ENV === 'production') {
// Set static folder
app.use(express.static('client/build'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}

相关内容

  • 没有找到相关文章

最新更新