簡體   English   中英

使用 heroku 更改 server.js 文件以將 socket.io 導出到 web

[英]Changing server.js file for exporting socket.io to the web using heroku

I am in the process of exporting a HTML5 project that uses socket.io and node.js, to the web, using heroku on the command line. 命令git push heroku master運行成功,游戲在 localhost 上運行。 但是,當使用heroku open時,即使與heroku ps:scale web=1一起使用,項目 javascript 似乎也無法連接到服務器。 Specifically, the html and css works, and the initial server message is displayed in the console, but the client never seems to send any information to the server with sockets.io.

我相信我需要更改 server.js 的初始行,但不確定如何更改。 這些行發布在下面:

    // Dependencies
var express = require('express');
var http = require('http');
var path = require('path');
var socketIO = require('socket.io');
var app = express();
var server = http.Server(app); 
var io = socketIO(server); 



     //App Setup
        enter code here`app.set('port',5000); 
        enter code here`app.use('/static',express.static(__dirname + '/static'));
        app.get('/', function(req, res) {
          res.sendFile(path.join(__dirname + '/index.html'));
        }); //USED TO BE THERE

        //Start the Server
        /*
        server.listen(5000,function() {
          console.log("Starting on localhost:50000");
        });
        */
         let port = process.env.PORT;
          if (port == null || port == "") {
            port = 8082;
          }

          server.listen(port, function () {
            console.log(`(1)Listening on ${server.address().port}`);
          });

客戶端的 javascript 位於與 server.js 相同目錄的 static/Game.js 中。 此外,這里是項目的 github 存儲庫: https://github.com/abinav-baskar/ColourGame

為准系統問題道歉。 如果我應該提供更多信息,或者研究,我應該自己做的故障排除,我會做的。 謝謝,

評論以將問題更新為“已解決”。 解決方案是針對我的情況的; 正如@Ameer 在對該問題的評論中所解釋的那樣,我的 html 的腳本標簽中存在大寫問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM