Node.js /socket.io/socket.io.js not found express 4.0

后端 未结 2 2004
野性不改
野性不改 2021-01-05 17:44

So I\'m trying to get chat working on my website, and when I was testing locally it worked great, because port 8080 on my localhost was available and all that good stuff. Bu

2条回答
  •  情话喂你
    2021-01-05 18:36

    What happens when you go to http://localhost:8080/socket.io/socket.io.js?

    Does it 404? If it does you need to make sure you have it in a directory that Express is set to serve statically.

    app.use(express.static(__dirname + '/public'));
    

    Then put your socket.io.js file in public/socket.io/socket.io.js (relative to your app.js file)

    Restart your server and see if that fixes it.

    Basically, Express doesn't serve files statically from the file system unless you explicitly tell it where to map from.

提交回复
热议问题