【发布时间】:2017-07-02 05:29:07
【问题描述】:
我设置了一个基本节点、express、react 应用程序,并且 express 正在提供静态内容,包括我的 css。当我查看源代码时,我注意到 index.html 在 head 标签中添加了这个:
<style type="text/css">* {}</style>
它绝对不在实际文件中。这是哪里来的?
另外,我没有在页面上看到我的实际 css 渲染。但是我确实看到 css 文件正在加载到 chrome 网络选项卡中。我也看到引导风格很好,它们的服务方式相同。这是怎么回事?
我的服务器:
var express = require('express'),
bodyParser = require('body-parser'),
http = require('http'),
path = require('path');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));
app.use(cors());
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
http.createServer(app).listen(8080), function () {
console.log('Express server listening on port 8080');
});
这就是我的css中的内容
body{
color: red;
}
【问题讨论】:
-
你在问为什么服务器会添加东西但没有关于服务器本身的信息......
-
index.html看起来像什么?此外,为了减少任何注入 CSS 的浏览器插件,您是否尝试在禁用所有扩展程序的情况下以隐身/私有方式加载页面? -
除非指定,否则服务器通常不会添加额外的数据。那条线应该有不同的原因。如果你能分享你的
index.html和你的css就更好了。 -
@godfrzero 它在隐身模式下消失了。哇,我没有意识到我有一个扩展添加。
-
@AnnaGarcia Adblockers 倾向于像这样注入 CSS,许多其他扩展也是如此。
标签: html css express server static-content