Angularjs + node + socket.io on localhost



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

我启动并运行了一切,如果我转到索引的位置.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

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

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);

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

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

最新更新