[英]Refused to apply style from 'xxx/style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type
I am new to Google App Engine and I'm trying to get the project I've been running locally hosted there.我是 Google App Engine 的新手,我正在尝试将我一直在本地运行的项目托管在那里。 My index.html shows up but it is not applying the CSS to it.我的 index.html 显示出来,但它没有应用 CSS。 I'm not exactly sure what a MIME type is, and I'm not exactly sure where in my code it's trying to get this from.我不确定 MIME 类型是什么,也不确定它试图从我的代码中的哪个位置获取它。 I just assumed that it would just load the tag that I have in my html and apply it like how it did while using browsersync.我只是假设它只会加载我在 html 中的标签,并像使用浏览器同步时那样应用它。 Index is loaded via:索引通过以下方式加载:
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '/index.html'));
});
CSS being loaded in index.html:在 index.html 中加载 CSS:
<link rel="stylesheet" type="text/css" href="style.css">
When you're returning the stylesheet from the server, you should set the content-type attribute for the header to text/css
ie you should have something like当您从服务器返回样式表时,您应该将标题的 content-type 属性设置为text/css
即您应该有类似的内容
<link href="style.css" rel="stylesheet" />
app.get('/style', (req, res) => {
res.setHeader('Content-Type', 'text/css');
res.sendFile(path.join(__dirname, '/style.css'));
});
app.get('/', (req, res) => {
res.setHeader('Content-Type', 'text/html');
res.sendFile(path.join(__dirname, '/index.html'));
});
The issue could probably be with the CSS library
starting with comments.问题可能出在以注释开头的CSS library
上。
In development, if the stylesheet is started with some comments, it could be seen as something different from CSS.在开发中,如果样式表以一些注释开头,则可以将其视为与 CSS 不同的东西。
Removing the library and putting it into a vendor file, may solve the issue.删除库并将其放入供应商文件中,可能会解决问题。
Another possibility for Node.js
applications is that you should check your configuration. Node.js
应用程序的另一种可能性是您应该检查您的配置。
Example:例子:
app.use(express.static(__dirname + ‘/public’));
Notice that /public does not have a forward slash at the end, so you will need to include it in your href option of your HTML:请注意, /public 末尾没有正斜杠,因此您需要将其包含在 HTML 的 href 选项中:
Example:例子:
href=”/css/style.css”>
If you did include a forward slash /public/
, then you can just do href=”css/style.css”>.
如果你确实包含了一个正斜杠/public/
,那么你可以只做href=”css/style.css”>.
Be sure that CSS name is style.css without the second s at the end, that could also cause the issue.确保 CSS 名称是 style.css 末尾没有第二个 s,这也可能导致问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.