我正在 AngularJS 中为 Node.js 中的后端创建一个前端。我可以选择使用两个简单的 Node.js 前端服务器来为前端网页提供服务:一个是 Express 中的简单 app.get,另一个是使用 http-server 包。
无论我使用哪种前端服务器代码,我都会在 Chrome 中收到以下浏览器控制台消息:
主线程上的同步 XMLHttpRequest 已被弃用,因为它会对最终用户的体验产生不利影响。如需更多帮助,请检查http://xhr.spec.whatwg.org/.
为了确保这不是由任何 Angular(或 Bootstrap)引起的,我已将网页削减为以下内容:
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>zoneshark</title>
</head>
<body>
<h1>Hello, world!</h1>
</body>
</html>
为什么我会收到错误消息? http-server 是否总是导致此错误?如何使用 Nodejs 设置前端服务器,以便不会发生此错误(只是这个简单的“hello world”页面将是一个起点)?
我用来替代 http-server 的服务器代码是:
var express = require('express');
var app = express();
app.get('/', function(req,res) {
res.sendFile('./index.html', {root: __dirname});
});
app.get(/^(.+)$/, function(req, res) {
res.sendFile('./' + req.params[0], {root: __dirname});
});
app.listen(80);
另一个奇怪的现象。从 http-server 控制台来看,http-server 似乎正在提供两个资源: /index.html 正如预期的那样,而且还有 /favicon.ico - 这很奇怪,因为在任何地方都没有提到这一点。
最后一个奇怪的地方:这只发生在 Chrome 上。在 IE 中没有问题,并且不需要 favicon.ico。
在 Chrome 中,我清除了除自动填充表单数据、密码和内容许可证之外的所有浏览数据。