简体   繁体   English

Heroku上的Node.js + Socket.io无法获取socket.io/socket.io.js

[英]Node.js + Socket.io on heroku fail to get socket.io/socket.io.js

First i'd like to thank you for taking the time to try to help me. 首先,我要感谢您抽出宝贵的时间来帮助我。

I'm trying to do a web application online using node.js and socket.io for realtime. 我正在尝试使用node.js和socket.io实时进行在线Web应用程序。 Here is my problem when i try my application in local it works but when i pushed it on heroku the server can't find my "herokuApp.heroku.com/socket.io/socket.io.js" 这是我在本地尝试应用程序时遇到的问题,但是当我在heroku上推送它时,服务器找不到我的“ herokuApp.heroku.com/socket.io/socket.io.js”

Of course i searched a lot for solve my problem but nothing here has solved it. 我当然搜索了很多解决我的问题的方法,但是这里没有任何解决方案。 Here is my files : 这是我的文件:

    var express = require('express');
var app = express(),
    server = require('http').createServer(app),
    io = require('socket.io').listen(server),
    ent = require('ent'), // Disable HTML caracters (equal htmlentities in PHP)
    fs = require('fs');


    app.use(express.static(__dirname + '/public_html'));
    app.set('port', (process.env.PORT || 5000));
    server.listen(5000);


    io.sockets.on('connection', function (socket) {

        socket.on("newMsg", function(data){
            console.log("the client message: " + msg);});

    });


    app.get('/', function(request, response) {
      response.send('Hello World!');
    });

    app.listen(app.get('port'), function() {
      console.log('Node app is running on port', app.get('port'));
    });

and in my index.html 在我的index.html中

<script src="/socket.io/socket.io.js"></script>

I add some information like the server response when i push my commit : http://puu.sh/irF05/e1c648c627.png 当我推送提交时,我添加了一些信息,例如服务器响应: http : //puu.sh/irF05/e1c648c627.png

and the structure of my files : http://puu.sh/irF8V/8240318ae6.png (the code above is from index.js and i don't use server.js) 和我的文件的结构: http : //puu.sh/irF8V/8240318ae6.png (上面的代码来自index.js,我不使用server.js)

Thanks you again for having read this, i'm not really familiar with node or socket so please excuse me if the solution is simple. 再次感谢您阅读本文,我对节点或套接字不是很熟悉,所以如果解决方案很简单,请原谅。

Make sure that socket.io.js is actually being pushed to the Heroku repository. 确保将socket.io.js实际推送到Heroku存储库。 Do a git status and make sure that it isn't untracked by git. 执行git status并确保它未被git跟踪。 Additionally, it might help if you post what your folder structure for this project looks like (at least the relevant files) 此外,如果发布该项目的文件夹结构(至少相关文件),可能会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM