简体   繁体   English

套接字无法在前端找到源文件

[英]Sockets can't find source files in frontend

Im using the template for express and angular from this tutorial. 我使用教程中的表达和角度模板。

Installed socket.io using npm and the files are visible in node_modules . 使用npm安装socket.io,文件在node_modules中可见。 Server starts normaly (I hope) with info - socket.io started visible in the console. 服务器启动正常(我希望)与info - socket.io started在控制台中info - socket.io started可见。

I run it by changing the server.js file from the template. 我通过从模板更改server.js文件来运行它。

var app = express()
    , server = http.createServer(app)
    , io = require('socket.io').listen(server)

and passing io to the files i'll be using it in like: 并将io传递给我将使用它的文件:

require('./config/routes')(app, passport, auth, io)

In the frontend (like in the example on sockets.io) website I add it by simply: 在前端(如sockets.io上的示例)网站我简单地添加它:

script(type='text/javascript', src='socket.io/socket.io.js')

but I get 但我明白了

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3000/socket.io/socket.io.js

Any help would be appreciated! 任何帮助,将不胜感激!

Check your code for the way you are initializing web server listener socket. 检查代码以了解初始化Web服务器侦听器套接字的方式。 This is not socket listener, but web server one. 这不是套接字侦听器,而是Web服务器。

In express it is usually: 在快递中通常是:

app.listen(3000);

But you need to do: 但你需要这样做:

server.listen(3000);

*Assuming that this is problem taking in account lack of full source code and missing exactly that part in your question code. *假设这是一个问题,考虑到缺少完整的源代码,并且在您的问题代码中缺少该部分。

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

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