有人可以帮助我在heroku上部署Node js应用程序。我有这个服务器,当我想在heroku上部署它时,只给出一个看起来像这样的错误。
2020-08-19T20:05:28.297858 + 00:00 heroku [router]:at =错误代码= H10 desc =“应用程序崩溃”,方法= GET path =“ /” host = mafia-go。 herokuapp.com request_id = de8a4648-e930-489c-b7ea-46dd688f6d75 fwd =“ 46.249.172.151” dyno = connect =服务=状态= 503字节=协议= https 2020-08-19T20:05:28.683186 + 00:00 heroku [router]:at =错误代码= H10 desc =“应用程序崩溃”方法= GET路径=“ / favicon.ico”主机= mafia-go.herokuapp.com request_id = 895eef65-0b37-439e-9fa8-e42f87feda00 fwd =“ 46.249.172.151” dyno = connect = service = status = 503字节= protocol = https
是的,我的包裹中有“开始”脚本。
这是我启动的服务器。
const HTTPS_PORT = process.env.PORT || 8443; //default port for https is 443
const HTTP_PORT = process.env.PORT || 8001; //default port for http is 80
const fs = require('fs');
const http = require('http');
const https = require('https');
const WebSocket = require('ws');
// based on examples at https://www.npmjs.com/package/ws
const WebSocketServer = WebSocket.Server;
// Yes, TLS is required
const serverConfig = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem'),
};
// ----------------------------------------------------------------------------------------
// Create a server for the client html page
const handleRequest = function (request, response) {
// Render the single client html file for any request the HTTP server receives
console.log('request received: ' + request.url);
if (request.url === '/webrtc.js') {
response.writeHead(200, { 'Content-Type': 'application/javascript' });
response.end(fs.readFileSync('client/webrtc.js'));
} else if (request.url === '/style.css') {
response.writeHead(200, { 'Content-Type': 'text/css' });
response.end(fs.readFileSync('client/style.css'));
} else {
response.writeHead(200, { 'Content-Type': 'text/html' });
response.end(fs.readFileSync('client/index.html'));
}
};
const httpsServer = https.createServer(serverConfig, handleRequest);
httpsServer.listen(HTTPS_PORT);
// ----------------------------------------------------------------------------------------
// Create a server for handling websocket calls
const wss = new WebSocketServer({ server: httpsServer });
wss.on('connection', function (ws) {
ws.on('message', function (message) {
// Broadcast any received message to all clients
console.log('received: %s', message);
wss.broadcast(message);
});
ws.on('error', () => ws.terminate());
});
wss.broadcast = function (data) {
this.clients.forEach(function (client) {
if (client.readyState === WebSocket.OPEN) {
client.send(data);
}
});
};
console.log('Server running.');
// ----------------------------------------------------------------------------------------
// Separate server to redirect from http to https
http.createServer(function (req, res) {
console.log(req.headers['host']+req.url);
res.writeHead(301, { "Location": "https://" + req.headers['host'] + req.url });
res.end();
}).listen(HTTP_PORT);