【问题标题】:Angularjs + node + socket.io on localhost本地主机上的 Angularjs + 节点 + socket.io
【发布时间】:2014-01-16 16:09:49
【问题描述】:

我正在使用 AngularJs、node 和 socket.io 来编写一个应用程序,我希望在我的不同客户端中有一些共享数据。我在看这个例子:https://github.com/mhevery/angular-node-socketio

如果我转到我的文件系统中的 index.html 的位置 (c:/user/angularnodesocket/index.html),我让一切都启动并运行,它工作正常,但是当我转到 localhost:8888 时网站仍然显示,但角度的东西没有被解释。

我在本地主机上收到此错误

Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:8888/bower_components/angular/angular.js". localhost/:4
Uncaught SyntaxError: Unexpected token < :8888/bower_components/angular/angular.js:1

谁能帮我看看这里发生了什么?

//G

【问题讨论】:

    标签: node.js angularjs socket.io localhost


    【解决方案1】:

    在该示例中,您使用的是以下代码

    http.createServer(function (request, response) {
            fs.readFile(__dirname+'/public/index.html', function (err, data) {
                    if (err) throw err;
                    response.setHeader("Content-Type", "text/html");
                    response.end(data);
            });
    }).listen(8888);
    

    返回 index.html 无论请求是什么。您的浏览器请求 angular.js 文件,但返回的是 index html,这会导致您看到错误消息。

    您必须修改 server.js 代码以支持静态文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-07
      • 2019-06-29
      • 2018-09-17
      • 2022-11-17
      • 2021-08-20
      • 2015-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多