【发布时间】:2018-04-01 07:45:38
【问题描述】:
我正在使用 ejs 处理 node.js(express),但我无法在其中包含 .css 文件 它浏览器显示以下错误。
localhost/:1 Refused to apply style from
'http://localhost:3000/posts/app.css' because its MIME type
('text/html') is not a supported stylesheet MIME type, and strict MIME
checking is enabled.
我的 app.js 是这样的:
var express = require('express');
var app = express();
app.use(express.static("public"));
app.get("/",function(req,res){
res.render("home.ejs");
});
app.get("/posts",function(req,res){
var posts = [
{title : "Post 1",author : "Malinda"},
{title : "Hello Sri Lankda",author : "Supun"},
{title : "Hello World",author : "Gokula"}
]
res.render("posts.ejs",{posts : posts});
});
app.listen(3000,function(){
console.log("Server Started");
});
和posts.ejs 文件
<link rel="stylesheet" type="text/css" href="app.css">
<h1>The Post Page</h1>
<p>Using For Loop</p>
<% for(var i =0; i < posts.length; i++){ %>
<li>
<%= posts[i].title%> - <strong><%= posts[i].author%></strong>
</li>
<% } %>
<br><br>
<p>Using For Each Loop</p>
<% posts.forEach(function(post){ %>
<li>
<%= post.title%> - <strong><%= post.author%></strong>
</li>
<% }) %>
和css文件
body{
background : yellow;
color : red;
}
请任何人帮我找出问题所在
【问题讨论】: